How to find the middle value of a n array
116 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Mario
el 1 de Jun. de 2015
Comentada: Harish Pulluri
el 18 de Mayo de 2016
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!!
0 comentarios
Respuesta aceptada
Guillaume
el 1 de Jun. de 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 comentarios
Harish Pulluri
el 18 de Mayo de 2016
But in case of even numbers which row it is considered as a middle row
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!