How to find the middle value of a n array

349 views (last 30 days)
Hello,
I have a 3x1 structure called sS, and inside that structure i have 3 arrays (323x2, 292x2 and 231x2) which contains 323, 292 and 231 X,Y coordinates, respectively.
I am trying from each of those three arrays somehow to extract this middle row inside (for eg. first array (323x2) that would be 161-st row which contains X,Y coordinates).
I tried with median but that is not what I need. I need to extract the middle row of all of my 3 arrays and store them in a new variable.
Maybe this seems trivial to someone, but I am having problems with it.
Can anybody help?
Thanks in advance!!

Accepted Answer

Guillaume
Guillaume on 1 Jun 2015
The structure bit is irrelevant. To get the middle row, you could simply do:
m = rand(323, 2); %for demo
midrow = m(ceil(end/2), :)
Not that for matrix with an even number of row, there is no one single middle row. The above will give you the first of the two middle rows.
  2 Comments
Mario
Mario on 1 Jun 2015
Thank you, that is exactly what I wanted.
Best regards!
Harish Pulluri
Harish Pulluri on 18 May 2016
But in case of even numbers which row it is considered as a middle row

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!