From: dpb on
Jan Simon wrote:
> Dear Luna!
>
>> dpb wrote:
>> rMax(1) = tmp(1);
>> for idx = 2:length(tmp)
>> rMax(idx) = max(rMax(idx-1), tmp(idx));
>> end
>
> Slightly faster, at least for my test data, so please test this by your
> own:
> b = tmp(1);
> for idx = 1:length(tmp)
> if tmp(idx) > b
> b = tmp(idx);
> end
> rMax(idx) = b;
> end

I had thought about posting a similar alternative as well, Jan...

I suppose the offset index is the culprit altho the max() call might be
something, too. I'm used to Fortran too much where such things end up
generally getting inlined automagically whereas they don't in ML, I
think, w/ JIT.

--


From: dpb on
Corey Kelly wrote:
....

>> An alternate way (without the loop) would be to make an array of
>> indices, and map the max function over the two arrays. The code will
>> be something like
>>
>> RunningMax = rm = arrayfun(@(a,b) max(a(1,1:b)),tmp,1:length(tmp))
>>
>> The idea is there, but something is wrong in my syntax. Perhaps an
>> expert could fix it up for us!
....

Not I, certainly... :)

I'm on a version that predates arrayfun() so I've no expertise/practice
there at all.

--
From: Bruno Luong on
Une impression de déjà vu:

http://www.mathworks.fr/matlabcentral/newsreader/view_thread/237000

Bruno
From: dpb on
Bruno Luong wrote:
> Une impression de déjà vu:
>
> http://www.mathworks.fr/matlabcentral/newsreader/view_thread/237000

I've noted a fair amount of that even in cssm... :(

--
First  |  Prev  | 
Pages: 1 2
Prev: read serial port in real time
Next: loading a file