At a given time frame, i have trajectories of 6 points having 6 X and 6 Y cordinates. I wish to calculate the distance between these points. Therefore, I will be obtaining 15 inter-point distances at a given frame. I wish to do so for n frames. Next, I would like to find the mean distance at a particular frame. How should I go about these? thank you in advance.
My data is in the form of text files (X and Y coordinates are in separate files- as attached).
Ishani
Edit: 15 inter-point distances, not 5 as pointed out by Chunru

댓글 수: 2

For 6 points having 6 X and 6 Y cordinates, you will have 5*6/2=15 paired distances.
doc pdist2
Thank you for your pointing this out. Yes, at a given time I will have 15 distances.

댓글을 달려면 로그인하십시오.

 채택된 답변

Chunru
Chunru 2022년 10월 12일
편집: Chunru 2022년 10월 12일
% xy = randn(6,2);
x = readmatrix("https://www.mathworks.com/matlabcentral/answers/uploaded_files/1153563/X_fragment1.txt");
y = readmatrix("https://www.mathworks.com/matlabcentral/answers/uploaded_files/1153573/Y_fragment1.txt");
whos
Name Size Bytes Class Attributes cmdout 1x33 66 char x 138x6 6624 double y 138x6 6624 double
nframes = size(x, 1);
dmean=zeros(nframes, 1);
for i=1:nframes
xy = [x(i,:)', y(i, :)'];
d = pdist2(xy, xy);
% extract the lower triangle
[ii, jj] = meshgrid(1:6, 1:6);
d1 = d(ii>jj); % d21, d31, ..., d61, d32, .., d62, ... d65
dmean(i) = mean(d1);
end
plot(1:nframes, dmean)
xlabel('frame number');
ylabel('mean distance')

댓글 수: 5

Ishani Mukherjee
Ishani Mukherjee 2022년 10월 12일
편집: Ishani Mukherjee 2022년 10월 12일
Thank you for the answer. I am unable to run this. My data is in the form of X coordintes in .txt and Y in .txt coordinates separately. Further I have data fragmented in 3 parts. Is that why the codes are not running?
Example X cordinates:
907.78 674.62 1011.5 1266.2 638.22
907.53 674.53 1014.1 1268.8 638.22
907.81 674.06 1018.4 1271.4 639.56
907.11 673.45 1020.1 1273.8 639.56
907.9 671.81 1024.6 1277.2 638.42
907.85 672.24 1027.7 1274.2 638.42
907.61 671.76 1030.1 1267.1 638.42
907.37 671.32 1033.4 1260.4 6
Chunru
Chunru 2022년 10월 12일
If you have difficulties reading the files, attach them in your post.
Thank you for the response. I have done so.
Chunru
Chunru 2022년 10월 12일
See the update for one group of data
It's working, thank you so much,

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Splines에 대해 자세히 알아보기

질문:

2022년 10월 12일

댓글:

2022년 10월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by