Selecting nearest data for one time
1 回表示 (過去 30 日間)
古いコメントを表示
Hi
I plot two cross sections like given in figure. Then i find the distance between O (center of cross section) and X. After that i find the nearest * to X and i calculated the distance bewteen * and O.Then i subtract the distances from each other. But i have a problem. I try to tell my problem on figure given below. For the X2 in figure, code gets the distance between O and X2 and then calculate distance between O and *b and then get the difference. That's fine. But for X1. It gets the distance between O and X1 then calculate the distance between O and *b again. But i wanted to get the distance between O and *a. Actually it is normal because *b is closere than *a. So i need to update the code. Every * have to be used only 1 time in calculations for the nearest X. How can i do it? Or is there another way to ensure it. Also i give the part of my code under the figure.
I hope i could tell what i mean
Thank you..
part of my code given below,
xz=[newVar(:,2) newVar(:,3)]
d1 = pdist2(newVar5,xz);
[~,idx5] = pdist2(newVar2,newVar,'euclidean','smallest',1);
xz2 = newVar2(idx5,:);
xz3=[xz2(:,2) xz2(:,3)]
d2 = pdist2(newVar5,xz3);
D=d2 - d1
newVar = raw data of X
newVar2 =raw data of *
newVar5 is the center of cross section (indicated with green O in figure)
xz indicated with blue X in figure
3 件のコメント
dpb
2019 年 8 月 3 日
OK, that eliminates the easiest...altho from the figure it looks like there are several instances of multiple x values between * which makes it appear there would be more x's than stars.
If that's just a plotting aberration and there really are even number of each and you want to progress to not reconsider the same 'x' a second time, then keep a separate "used" logical vector and mark each location which is used when it is taken and then remove the data for that index from the searchable array...this could be done by using a logical array as the index of the x data array instead of the whole array and by setting the given index to false so it doesn't appear in the search of x values to be reselected a second time.
回答 (1 件)
Bhargavi Maganuru
2019 年 8 月 5 日
There is a similar question which may be of relevance to you : https://www.mathworks.com/matlabcentral/answers/464446-distance-difference-from-center?s_tid=answers_rc1-1_p1_BOTH
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Resizing and Reshaping Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!