From: Luna Moon on 18 Jan 2010 22:07 Here is an simple implementation. But I need to run this as an inner loop millions of times... How to make it more efficient? Hopefully without the for loop? Thanks! nMax=data(1); for i=2: length(data) nMax=max(data(i), nMax); end;
From: ImageAnalyst on 18 Jan 2010 22:16 Won't this finally just end up with the max value of the entire array? So why don't you just call the max() function? If you want the max in a sliding window, then use the imdilate() function in the image processing toolbox.
From: Bruno Luong on 19 Jan 2010 02:45 Luna Moon <lunamoonmoon(a)gmail.com> wrote in message <c40bfd10-6b56-40e4-adb4-84968cd1e9d0(a)g25g2000yqd.googlegroups.com>... > Here is an simple implementation. But I need to run this as an inner > loop millions of times... > > How to make it more efficient? Hopefully without the for loop? > > Thanks! > > nMax=data(1); > > for i=2: length(data) > > nMax=max(data(i), nMax); > > end; Simply nMax = max(data) as IA suggested earlier. Bruno
From: Luna Moon on 19 Jan 2010 08:16 On Jan 19, 2:45 am, "Bruno Luong" <b.lu...(a)fogale.findmycountry> wrote: > Luna Moon <lunamoonm...(a)gmail.com> wrote in message <c40bfd10-6b56-40e4-adb4-84968cd1e...(a)g25g2000yqd.googlegroups.com>... > > Here is an simple implementation. But I need to run this as an inner > > loop millions of times... > > > How to make it more efficient? Hopefully without the for loop? > > > Thanks! > > > nMax=data(1); > > > for i=2: length(data) > > > nMax=max(data(i), nMax); > > > end; > > Simply > nMax = max(data) > > as IA suggested earlier. > > Bruno Sorry I didn't make it clear. nMax need to be a vector of max's at that point...so called running max... for i=1:length(data); nMax(i)=max(data(1:i)) end;
From: Oliver Woodford on 19 Jan 2010 08:31
Luna Moon <lunamoonmoon(a)gmail.com> wrote in message <375ff86d-0264-4b0d-941c-060826c9f9ce(a)v25g2000yqk.googlegroups.com>... > On Jan 19, 2:45 am, "Bruno Luong" <b.lu...(a)fogale.findmycountry> > wrote: > > Luna Moon <lunamoonm...(a)gmail.com> wrote in message <c40bfd10-6b56-40e4-adb4-84968cd1e...(a)g25g2000yqd.googlegroups.com>... > > > Here is an simple implementation. But I need to run this as an inner > > > loop millions of times... > > > > > How to make it more efficient? Hopefully without the for loop? > > > > > Thanks! > > > > > nMax=data(1); > > > > > for i=2: length(data) > > > > > nMax=max(data(i), nMax); > > > > > end; > > > > Simply > > nMax = max(data) > > > > as IA suggested earlier. > > > > Bruno > > Sorry I didn't make it clear. > > nMax need to be a vector of max's at that point...so called running > max... > > for i=1:length(data); > nMax(i)=max(data(1:i)) > end; Write a C mex file containing the following code: nMax[0] = data[0]; for (int a = 1; a < len; ++a) nMax[a] = nMax[a-1] > data[a] ? nMax[a-1] : data[a]; |