MATLAB Answers

How can I change my for loop to interpret different columns?

3 ビュー (過去 30 日間)
Ivana Mora
Ivana Mora 2017 年 11 月 6 日
回答済み: Robert 2017 年 11 月 6 日
for i = 1:length (key)
key_vec (i)= raw {2, i+6};
stu1_multi_choice_vec (i) = raw {3, i+6};
no_correct_stu1_vec = no_correct_stu1_vec + ...
strcmp (key_vec (i), stu1_multi_choice_vec (i));
I was given an excel spreadsheet with the answers of 116 students. I have this which tells me the number correct for the first student but I need to figure out how to extend that down the column to all 116 students so I can graph the data?

  1 件のコメント

Jan 2017 年 11 月 6 日
I do not understand the question. What do you want extend by what and what exactly does "graph the data" mean? Do you want to solve this in Matlab or in Excel?


回答 (1 件)

Robert 2017 年 11 月 6 日
I am guessing that your Excel spreadsheet has a header row, an answer key row, then a row per student with their answers. You imported the excel data as a cell array of strings called raw. Also, the first six rows are not used here; the first question's key and answers are in column 7. Is that correct?
If so, try the following:
Extract your data from the raw cell array
key = raw(2, 7:end);
answers = raw(3:end, 7:end);
Compare it all at once using strcmp
num_correct = sum(strcmp(answers, repmat(key, num_students, 1)), 2);
Plot the results as a bar chart
No for loops needed!

  0 件のコメント



Community Treasure Hunt

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

Start Hunting!

Translated by