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

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

find( strcmp(grades{:,1}, answer{1}) )

2 Comments

So that worked for finding the corresponding row, but how do I retrieve the GPA from the second column for the found row number?
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

Products

Release

R2018b

Community Treasure Hunt

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

Start Hunting!