Finding closest points to a given range in matrix
古いコメントを表示
Hi,
I have a 3 column matrix, x,y,and z respectively. I want to obtain the value of z corresponds to (closest point to 0.00 in x), and closest point to 0.29 in y) (both conditions must be satisfied in the same row).
To sum , for example, x range is between 0.00 and 0.02, and that of y is between 0.28 and 0.29). At the end, I may obtain the values as x=0.0005, its corresponding y=0.28 and (z=-0.3355)
I investigated in the forum but could not find a solution. Could you kindly give me some advice for this?
Thanks in advance.
採用された回答
その他の回答 (3 件)
Fangjun Jiang
2011 年 12 月 13 日
The closet point to 0 in x might have one point. The closet point to 0.29 might also have one point. What if they are not in the same row? Does't it mean you don't have a solution.
xyz=rand(20,3);
[MinX,Indx]=min(abs(xyz(:,1)))
[MinY,IndY]=min(abs(xyz(:,2)-0.29));
if MinX~=MinY
disp('no solutin');
else
FoundZ=xyz(IndX,3);
end
Mads
2011 年 12 月 13 日
0 投票
If A is your matrix you could use:
[~,b] = min(abs(A(:,1))+abs(A(:,2)-0.29))
where b is the rows position which satisfies being the minimum absolute distance to the point.
tethys
2011 年 12 月 13 日
0 投票
6 件のコメント
Fangjun Jiang
2011 年 12 月 13 日
Do you understand my point in my answer? Or maybe you didn't describe your question correctly. Could you provide a set of example data (the nx3 matrix) and then explain the expected output?
tethys
2011 年 12 月 13 日
tethys
2011 年 12 月 13 日
Fangjun Jiang
2011 年 12 月 13 日
So are you looking for a point of (x,y) which is the closet to (0,0.28), which means sqrt(x^2+(y-0.28)^2)? That is different than "x close to 0" and "y close to 0.28".
Sean de Wolski
2011 年 12 月 13 日
BSXFUN is in kaan's future!
tethys
2011 年 12 月 13 日
カテゴリ
ヘルプ センター および File Exchange で Mathematics についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!