Selecting nearest data for one time

조회 수: 1 (최근 30일)
Mehmet Volkan Ozdogan
Mehmet Volkan Ozdogan 2019년 8월 2일
답변: Bhargavi Maganuru 2019년 8월 5일
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일
편집: 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
Bhargavi Maganuru 2019년 8월 5일

카테고리

Help CenterFile Exchange에서 Time Series에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by