find array maximun in matrix

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

find array maximun in matrix

Octave - General mailing list
hi, look that:

a=[4 6 1 6  7 9 1 2 3 4]


i want to find maximun series in matrix:

ans: [4 6 6 6 7 9 9 9 9 9]

i can to do this:

maxx=a(1);

for i=2:length(a)
   if a(i)>maxx(i-1)
     maxx(end+1)=a(i);
  endif
end

but I wanted to write a faster code avoiding the cycle



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: find array maximun in matrix

nrjank
On Mon, May 13, 2019 at 1:22 PM shivax via Help-octave <[hidden email]> wrote:
hi, look that:

a=[4 6 1 6  7 9 1 2 3 4]


i want to find maximun series in matrix:

ans: [4 6 6 6 7 9 9 9 9 9]

i can to do this:

maxx=a(1);

for i=2:length(a)
   if a(i)>maxx(i-1)
     maxx(end+1)=a(i);
  endif
end

but I wanted to write a faster code avoiding the cycle


the function cummax  (cumulative or running maximum) will do this for you 


Reply | Threaded
Open this post in threaded view
|

Re: find array maximun in matrix

Octave - General mailing list