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..
unt2.jpg
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 个评论
Mehmet Volkan Ozdogan
编辑:Mehmet Volkan Ozdogan 2019-8-3
Yes it has same number of observation.They have both 100 data. Do you have any suggesiton about my problem. X and * ar not in same order... Thank you..
dpb
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

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by