MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: message 50001?


Hi,

data = Table[If[i == 20, 100*Random[], Random[]], {i, 100}];

i = 1;
MapIndexed[If[#1 > data[[i]], i = #2[[1]]] &, data];
{i, data[[i]]}

or

p = Position[#, peak = Max[#]] &[data];
{p[[1,1]], peak}

Regards
  Jens

"1.156" wrote:
> 
> Mathematica wizards, I've managed to cripple together code to do something that
> I feel must be doable more easily and/or faster.
> 
> S is a list of reals containing a signal with a prominent peak in
> amplitude. I simply want to find the index of the peak (x, the number of
> entries into the list where the peak occurs). Here's what I did.
> 
> For[i = 1, S[[i]] ? max[S], i++, x = i];
> 
> Can some suggest a better way, especially one not using a For loop?
> 
> Thanks, Rob


  • Prev by Date: Re: message 50001?
  • Next by Date: Re: Re: How to set linewidth in 3-D graphics?
  • Previous by thread: Re: message 50001?
  • Next by thread: Re: message 50001?