How to extract specific values from a table
이전 댓글 표시
Dear All I'm aiming to measure the distance between all points in one frame and all points in the next frame. So I want to Create a table (let’s call this “table i”)which only contains points in frame i (where “i" is the index of that frame) Create another table (“table i+1”), which only contains points in frame i+1 Create a 2D distance matrix (width equal to the number of points in frame i and height equal to the number of points in frame i+1) where each element is the Pythagoras distance between two points. How can I implement this as a code ? Thank you
댓글 수: 7
Adam Danz
2019년 7월 15일
This question is an extension of a previous question:
I recommend not breaking up your table into multiple tables. Instead, use indexing to identify all points in frame i and another index variable to identify all points in frame i-1. Then you just need to use those two index variables to send the (x,y) coordinates into the distance formula we discussed in your previous question.
karishma koshy
2019년 7월 15일
편집: karishma koshy
2019년 7월 15일
karishma koshy
2019년 7월 17일
편집: karishma koshy
2019년 7월 17일
Adam Danz
2019년 7월 17일
There are 30 coordinates in each frame. Let's call them c1,c2, c3....c30. Do you want the distance between c1 in frame 1 and [c1:c30] in frame 2? And do you want those distances for all points and between all 1000 frames?
I ask these questions because I'm unsure how you want to organize the data.
For example, do you want a [30 x 30 x 1000] array named A where A(i,j,k) is the distance between xy(i) and xy(j) from frame (k-1) to frame (k)?
This should be well defined before moving forward.
karishma koshy
2019년 7월 17일
편집: karishma koshy
2019년 7월 17일
Adam Danz
2019년 7월 17일
Following my example in my answer, here's how to calculate the distance between point 'p' in frame 'f' to all points in frame 'f+1'.
The example shows distances between the 3rd point of frame 4 and all points in frame 5.
f = 4; %frame number 1:1000
p = 3; %point number (within frame) 1:30
% Find distance between point p of frame f and all points in frame f+1
fIdx = T.Frame == f; %index for frame f
f2Idx = T.Frame == f+1; %index for frame f+1
pIdx = max(find(fIdx,p)); %index of point p in frame f
d = pdist2([T.centreX(pIdx),T.centreY(pIdx)],[T.centreX(f2Idx),T.centreY(f2Idx)])';
Note that d(p) should be 0 since the (x,y) coordinates do not change between frames.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Test and Measurement에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!