Finding Middlemost row in a matrix
显示 更早的评论
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 个评论
Stephen23
2017-11-6
What does "middlemost" mean ?
mr mo
2017-11-6
Stephen23
2017-11-6
What does "middle point" mean ?
mr mo
2017-11-6
Birdman
2017-11-6
Check my answer.
mr mo
2017-11-6
@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
2017-11-6
Jan
2017-11-6
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
2017-11-6
采纳的回答
更多回答(1 个)
Image Analyst
2017-11-6
Try mean() or median():
columnMedians = median(A, 1)
columnMeans = mean(A, 1)
depending on what "middlemost" means to you.
4 个评论
@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.
类别
在 帮助中心 和 File Exchange 中查找有关 Resampling Techniques 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!