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

조회 수: 2 (최근 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));
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
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
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!

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by