How to find the middle value of a n array

279 次查看(过去 30 天)
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!!

采纳的回答

Guillaume
Guillaume 2015-6-1
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 个评论
Mario
Mario 2015-6-1
Thank you, that is exactly what I wanted.
Best regards!
Harish Pulluri
Harish Pulluri 2016-5-18
But in case of even numbers which row it is considered as a middle row

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by