how to get maximum last n element in array

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

how to get maximum last n element in array

LucaLuca
hi,

i've matrix A

i want to know the maximun value of last n element





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


Reply | Threaded
Open this post in threaded view
|

Re: how to get maximum last n element in array

Andreas Weber-6
Am 06.07.2018 um 15:33 schrieb LucaLuca:
> i want to know the maximun value of last n element

please explain. Of last n elements in each row or column?
Please create a MCVE


Reply | Threaded
Open this post in threaded view
|

RE: how to get maximum last n element in array

Allen.Windhorn-3
In reply to this post by LucaLuca
> -----Original Message-----
> From: Help-octave [mailto:help-octave-
>
> i've matrix A
>
> i want to know the maximum value of last n element

A = 1:22

 Columns 1 through 17:

    1    2    3    4    5    6    7    8    9   10   11   12   13   14   15   16   17

 Columns 18 through 22:

   18   19   20   21   22

>> n = 6
>> A(end-n+1:end) # Last n elements
ans =

   17   18   19   20   21   22

>> max(A(end-n+1:end)) # Max of last n elements
ans =  22

Regards,
Allen


Reply | Threaded
Open this post in threaded view
|

Re: how to get maximum last n element in array

LucaLuca
This post was updated on .
In reply to this post by Andreas Weber-6
if i set columns=1  i want to know the last n element of M[:,1]

the maximum of last n element

example:

  [1,1] =  1
  [1,2] =  34
  [1,3] =  4
  [1,4] =  5
  [1,5] =  6
  [1,6] =  1
  [1,7] =  2
  [1,8] =  3
  [1,9] =  4

the maximum of last 5 element is 6 (6,1,2,3,4 ===>6)


Andreas...what is MCVE ?


thanks Allen.Windhorn for helping


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