28 views (last 30 days)

Adam Danz
on 15 Jul 2019

Edited: Adam Danz
on 16 Jul 2019

If I understand your question correctly, you want to measure the distance each (x,y) coordinate travels between frames. Is that correct? It looks like the (x,y) centers of your circles do not change between frames. For example, the first (x,y) coordinate at frame 1 is (144.09, 131,56) and this coordinate is the same for frame 2, 3, etc... When I run the code below, the distance is always 0. Maybe I'm not understanding your problem.

%% Import data and store in table "T"

opts = spreadsheetImportOptions("NumVariables", 4);

opts.Sheet = "in";

opts.DataRange = "A2:D30001";

opts.VariableNames = ["centreX", "centreY", "Radius", "Frame"];

opts.SelectedVariableNames = ["centreX", "centreY", "Radius", "Frame"];

opts.VariableTypes = ["double", "double", "double", "double"];

T = readtable("C:\Users\adanz\Documents\MATLAB\savehere\matlabCentralDocs_trash\DataTable_SER.xlsx", opts, "UseExcel", false);

%% Calculate distance between frames

nFrames = max(T.Frame);

distFcn = @(x1,x2,y1,y2)sqrt((x2-x1).^2 + (y2-y1).^2); %distance function

dist = nan(sum(T.Frame == 1), nFrames-1); %assumes there are an equal number of frames for all frames

for i = 2:nFrames

% Index for frame i

idx2 = T.Frame == i;

% Index for frame i-1

idx1 = T.Frame == i-1;

% Calculate distance

dist(:,i-1) = distFcn(T.centreX(idx2),T.centreX(idx1),T.centreY(idx2),T.centreY(idx1));

end

Sign in to comment.

Sign in to answer this question.

Opportunities for recent engineering grads.

Apply Today
## 7 Comments

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/471775-how-to-extract-specific-values-from-a-table#comment_724652

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/471775-how-to-extract-specific-values-from-a-table#comment_724652

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/471775-how-to-extract-specific-values-from-a-table#comment_724655

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/471775-how-to-extract-specific-values-from-a-table#comment_724655

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/471775-how-to-extract-specific-values-from-a-table#comment_725397

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/471775-how-to-extract-specific-values-from-a-table#comment_725397

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/471775-how-to-extract-specific-values-from-a-table#comment_725404

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/471775-how-to-extract-specific-values-from-a-table#comment_725404

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/471775-how-to-extract-specific-values-from-a-table#comment_725434

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/471775-how-to-extract-specific-values-from-a-table#comment_725434

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/471775-how-to-extract-specific-values-from-a-table#comment_725436

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/471775-how-to-extract-specific-values-from-a-table#comment_725436

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/471775-how-to-extract-specific-values-from-a-table#comment_725441

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/471775-how-to-extract-specific-values-from-a-table#comment_725441

Sign in to comment.