Finding Middlemost row in a matrix
Mostrar comentarios más antiguos
Hi. Suppose I have a (m*n) matrix A e.g.
A=[8.9505 4.8075 1.6187 0.0020
8.9755 4.7575 1.6187 0.0020
8.9755 4.7825 1.6187 0.0020
8.9755 4.8075 1.6187 0.0020
8.9755 4.8325 1.6187 0.0020
8.9755 4.8575 1.6187 0.0020
9.0005 4.7325 1.6187 0.0020
9.0005 4.7575 1.6187 0.0020
9.0005 4.7825 1.6187 0.0020
9.0005 4.8075 1.6187 0.0020
9.0005 4.8325 1.6187 0.0020
9.0005 4.8575 1.6187 0.0020
9.0255 4.7325 1.6187 0.0020
9.0255 4.7575 1.6187 0.0020
9.0255 4.7825 1.6187 0.0020
9.0255 4.8075 1.6187 0.0020
9.0255 4.8325 1.6187 0.0020
9.0255 4.8575 1.6187 0.0020
9.0505 4.7325 1.6187 0.0020
9.0505 4.7575 1.6187 0.0020
9.0505 4.7825 1.6187 0.0020
9.0505 4.8075 1.6187 0.0020
9.0505 4.8325 1.6187 0.0020
9.0755 4.7575 1.6187 0.0020
9.1255 4.6075 1.6187 0.0020
9.1505 4.5825 1.6187 0.0020
9.1505 4.6075 1.6187 0.0020
9.1755 4.5825 1.6187 0.0020
9.2005 4.5575 1.6187 0.0020];
Imagine that the first column is X coordinates and second column is Y coordinates of some points.
In the matrix A, the first column values varied form minimum value 8.9505 to maximum value 9.2005, and the second column values varied form minimum value 4.5575 to maximum value 4.8575
The middle point of column 1 is :
(8.9505 + 9.2005)/2 = 9.0755
and the middle point of column 2 is:
(4.5575 + 4.8575)/2 = 4.7075
I want to find which one of the rows of matrix A has the nearest values to these values in its first and second columns respectively. Thanks
11 comentarios
Stephen23
el 6 de Nov. de 2017
What does "middlemost" mean ?
mr mo
el 6 de Nov. de 2017
Stephen23
el 6 de Nov. de 2017
What does "middle point" mean ?
mr mo
el 6 de Nov. de 2017
Birdman
el 6 de Nov. de 2017
Check my answer.
mr mo
el 6 de Nov. de 2017
@mr mo: You still do not explain, how "middlemost" is defined mathematically. You give one example, but it is not a clear and unique definition. It is not efficient to let the readers guess.
You mention "8.9505 + 9.2005" for the first column. This can be the smallest and largest value, or the first an the last- this is the same, because the 1st column seems to be sorted. But the second is not. Do you mean the first and last element or the smallest and largest?
You forgot to explain, what should happen, if multiple elements have the same value, if it is has minimal distance. What is "the middlemost point" in [1,2,3,4]? Or [1,2.5,2.5,4]?
What is the wanted output for your example? 19? Or A(19, :)? Or do you want an answer for each column?
You make it really hard to help you.
mr mo
el 6 de Nov. de 2017
Jan
el 6 de Nov. de 2017
Okay, this point is clear now. The proceed with the next step: How do you want to measure the distance: https://www.mathworks.com/matlabcentral/answers/365367-finding-middlemost-row-in-a-matrix#comment_501744
mr mo
el 6 de Nov. de 2017
Respuesta aceptada
Más respuestas (1)
Image Analyst
el 6 de Nov. de 2017
Try mean() or median():
columnMedians = median(A, 1)
columnMeans = mean(A, 1)
depending on what "middlemost" means to you.
4 comentarios
@mr mo: You still did not define, what "middlemost" means. Now we know, that it is "based on values in the first and second column of matrix A", but how is it determined without using a kind of mean?
You have used "middlemost" 18 times now, but it is not clear, what its mathematical meaning is.
Stephen23
el 6 de Nov. de 2017
Categorías
Más información sobre Resampling Techniques en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!