Reading a table and finding a specific value that corresponds to another
1 view (last 30 days)
Show older comments
J Morgan Alsbrook
on 29 Nov 2019
Commented: Walter Roberson
on 29 Nov 2019
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.
0 Comments
Accepted Answer
Walter Roberson
on 29 Nov 2019
find( strcmp(grades{:,1}, answer{1}) )
2 Comments
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};
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!