How to obtain values from a table in matlab (2024)

3 views (last 30 days)

Show older comments

karishma koshy on 14 Jul 2019

  • Link

    Direct link to this question

    https://www.mathworks.gr/matlabcentral/answers/471679-how-to-obtain-values-from-a-table-in-matlab

  • Link

    Direct link to this question

    https://www.mathworks.gr/matlabcentral/answers/471679-how-to-obtain-values-from-a-table-in-matlab

Edited: karishma koshy on 15 Jul 2019

Accepted Answer: Adam Danz

  • DataTable_SER.xlsx

I have a table with two columns as circle's centre position and third one with frame number 1-1000. I want to obtain the values of circle centres in frame n and n-1 at a time, inorder to make matrix out of it

How can I do that?

0 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

Sign in to answer this question.

Accepted Answer

Adam Danz on 14 Jul 2019

  • Link

    Direct link to this answer

    https://www.mathworks.gr/matlabcentral/answers/471679-how-to-obtain-values-from-a-table-in-matlab#answer_383177

Edited: Adam Danz on 14 Jul 2019

I'm not sure what you mean by "in order to make a matrix out of it". If this demo doesn't address the problem, please provide an example. Otherwise, here's how to extract the (x,y) coordinates for a given frame.

%Fake data

T = table((1:9)',(2:10)',[1;1;1;2;2;2;3;3;3],'VariableNames',{'X','Y','Frame'});

f = 2; % frame number

frameIdx = T.Frame == f; %row numbers of frame n

frameIdx = T.Frame == f-1; %row numbers of frame n-1 (not used in this demo)

% FROM HERE YOU CAN DO LOTS OF THINGS LIKE...

% ...isolate rows of table that belong to frame n

T(frameIdx,:)

% ...isolate only the (X,Y) values that belong to frame n

T(frameIdx,{'X','Y'})

% ...put (X,Y) values from frame n into a matrix

T{frameIdx,{'X','Y'}}

I recommend keeping the data in the table rather than extracting it into a matrix unless your analysis requres a matrix.

5 Comments

Show 3 older commentsHide 3 older comments

karishma koshy on 14 Jul 2019

Direct link to this comment

https://www.mathworks.gr/matlabcentral/answers/471679-how-to-obtain-values-from-a-table-in-matlab#comment_724418

  • Link

    Direct link to this comment

    https://www.mathworks.gr/matlabcentral/answers/471679-how-to-obtain-values-from-a-table-in-matlab#comment_724418

Im actually trying to do munkres Hungarian algorithm. So I want to find the position difference of a particular circle from one frame to another frame. The circle represents the bacteria, and it's actually moving.

How can I find the distance between points.

Adam Danz on 14 Jul 2019

Direct link to this comment

https://www.mathworks.gr/matlabcentral/answers/471679-how-to-obtain-values-from-a-table-in-matlab#comment_724420

  • Link

    Direct link to this comment

    https://www.mathworks.gr/matlabcentral/answers/471679-how-to-obtain-values-from-a-table-in-matlab#comment_724420

Edited: Adam Danz on 15 Jul 2019

"How can I find the distance between points."

Distance = sqrt((x2-x1)^2 + (y2-y1)^2)

Thanks to Pythagoras.

(x1,y1) are the coordinates at frame n; (x2,y2) are coordinates at frame n-1 (or the other way around; it doesn't matter).

karishma koshy on 14 Jul 2019

Direct link to this comment

https://www.mathworks.gr/matlabcentral/answers/471679-how-to-obtain-values-from-a-table-in-matlab#comment_724423

  • Link

    Direct link to this comment

    https://www.mathworks.gr/matlabcentral/answers/471679-how-to-obtain-values-from-a-table-in-matlab#comment_724423

Dear sir

Can you help me construct a for loop to find the distance between loops in n and n-1 frames and terminate the loop when it's reached the last value of both the frames

Adam Danz on 15 Jul 2019

Direct link to this comment

https://www.mathworks.gr/matlabcentral/answers/471679-how-to-obtain-values-from-a-table-in-matlab#comment_724430

  • Link

    Direct link to this comment

    https://www.mathworks.gr/matlabcentral/answers/471679-how-to-obtain-values-from-a-table-in-matlab#comment_724430

The loop will probably look something like this; T is your table.

% Create fake data

T = table((1:9)',(2:10)',[1;1;1;2;2;2;3;3;3],'VariableNames',{'X','Y','Frame'});

n = size(T,1)'; %number of rows in your table

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

% Loop through each row starting at row #2

d = zeros(n-1,1); %create a vector where the distances will be stored

for i = 2:n

d(i-1) = distFcn(T.X(i-1),T.X(i),T.Y(i-1),T.Y(i));

end

And you can do that without a loop, too.

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

% ^ ^ note the dots

d = distFcn(T.X(2:end),T.X(1:end-1),T.Y(2:end),T.Y(1:end-1))

karishma koshy on 15 Jul 2019

Direct link to this comment

https://www.mathworks.gr/matlabcentral/answers/471679-how-to-obtain-values-from-a-table-in-matlab#comment_724633

  • Link

    Direct link to this comment

    https://www.mathworks.gr/matlabcentral/answers/471679-how-to-obtain-values-from-a-table-in-matlab#comment_724633

Edited: karishma koshy on 15 Jul 2019

Dear Sir 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

Sign in to comment.

More Answers (0)

Sign in to answer this question.

See Also

Categories

MATLABData Import and AnalysisData Import and ExportStandard File FormatsLaTeX

Find more on LaTeX in Help Center and File Exchange

Tags

  • extract data from table in matlab

Community Treasure Hunt

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

Start Hunting!

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.


How to obtain values from a table in matlab (8)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list

Americas

Europe

Asia Pacific

Contact your local office

How to obtain values from a table in matlab (2024)

References

Top Articles
Latest Posts
Article information

Author: Zonia Mosciski DO

Last Updated:

Views: 6266

Rating: 4 / 5 (71 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Zonia Mosciski DO

Birthday: 1996-05-16

Address: Suite 228 919 Deana Ford, Lake Meridithberg, NE 60017-4257

Phone: +2613987384138

Job: Chief Retail Officer

Hobby: Tai chi, Dowsing, Poi, Letterboxing, Watching movies, Video gaming, Singing

Introduction: My name is Zonia Mosciski DO, I am a enchanting, joyous, lovely, successful, hilarious, tender, outstanding person who loves writing and wants to share my knowledge and understanding with you.