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

1 visualización (últimos 30 días)
Ivana Mora
Ivana Mora el 6 de Nov. de 2017
Respondida: Robert el 6 de Nov. de 2017
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 comentario
Jan
Jan el 6 de Nov. de 2017
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?

Iniciar sesión para comentar.

Respuestas (1)

Robert
Robert el 6 de Nov. de 2017
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!

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by