Reading a table and finding a specific value that corresponds to another

10 views (last 30 days)
I am trying to write a .m script so that it imports a excel file and compares the data that I enter to the imported table. Column 1 of the table is 1A,1B 2A, 2B. Column 2 of the table is the GPA. What I am trying to do is input an academic class and current gpa and I want it to go to the table and find that academic class and avg all the gpa's next to those academic classes and assign it to a variable. For some reason I cannot get the find command to work. Attached is my code and outputs seen in Matlab.

Accepted Answer

Walter Roberson
Walter Roberson on 29 Nov 2019
find( strcmp(grades{:,1}, answer{1}) )
  2 Comments
J Morgan Alsbrook
J Morgan Alsbrook on 29 Nov 2019
So that worked for finding the corresponding row, but how do I retrieve the GPA from the second column for the found row number?
Walter Roberson
Walter Roberson on 29 Nov 2019
mask = strcmp(grades{:,1}, answer{1});
retrieved_gpa = grades{mask, 2};
If you prefer to stick with find() instead of logical masks then
rownum = find(strcmp(grades{:,1}, answer{1}));
retrieved_gpa = grades{rownum, 2};

Sign in to comment.

More Answers (0)

Categories

Find more on Tables in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!