MATLAB Answers

0

Selecting nearest data for one time

Asked by Mehmet Volkan Ozdogan on 2 Aug 2019
Latest activity Answered by Bhargavi Maganuru on 5 Aug 2019
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 Comments

dpb
on 3 Aug 2019
Is there a 1:1 mapping of a '*' and an 'x'? IOW, are there the same number of observations for each? Seems to meet the criterion of "Every * have to be used only 1 time in calculations for the nearest X". But, in that case it really isn't the nearest x in distance but the next one after the previous one was used up.
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
on 3 Aug 2019
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.

Sign in to comment.

1 Answer

Answer by Bhargavi Maganuru on 5 Aug 2019

  0 Comments

Sign in to comment.