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

1 回表示 (過去 30 日間)
J Morgan Alsbrook
J Morgan Alsbrook 2019 年 11 月 29 日
コメント済み: Walter Roberson 2019 年 11 月 29 日
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.

採用された回答

Walter Roberson
Walter Roberson 2019 年 11 月 29 日
find( strcmp(grades{:,1}, answer{1}) )
  2 件のコメント
J Morgan Alsbrook
J Morgan Alsbrook 2019 年 11 月 29 日
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 2019 年 11 月 29 日
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};

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by