How can I change my for loop to interpret different columns?
2 次查看(过去 30 天)
显示 更早的评论
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));
end
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
bar(num_correct)
No for loops needed!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!