Asked by Mehmet Volkan Ozdogan
on 2 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..

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

Answer by Bhargavi Maganuru
on 5 Aug 2019

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 3 Comments

## dpb (view profile)

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/474661-selecting-nearest-data-for-one-time#comment_731503

## Mehmet Volkan Ozdogan (view profile)

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/474661-selecting-nearest-data-for-one-time#comment_731567

## dpb (view profile)

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/474661-selecting-nearest-data-for-one-time#comment_731572

Sign in to comment.