Cell array indexing question
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Brittany Isbister
le 20 Fév 2021
Réponse apportée : Stephen23
le 22 Fév 2021
Hi All,
I'm trying to have it so that this will loop thorugh and put all the numbers/ characters in for the different places in the fprintf statement. I have it so it will run the name, but after that it won't run the right thing. Any help would be appreciated!
%% Part A
load('QuizGrades.mat')
student_Names={'Student1','Student2','Student3','Student4','Student5','Student6','Student7','Student8','Student9','Student10','Student11','Student12','Student13','Student14'};
student_IDs=[101:114];
grade_Book={student_Names,student_IDs,grades}
cellplot(grade_Book)
%% Part B
mean(grade_Book{3}(3,:))% mean of the quiz grades for student 3
mean(grade_Book{3}(:,5))% mean of student grades on quiz 5
mean(grade_Book{3}())% mean of grades for all quizzes
%% Part C
[M,I]=min(grade_Book{3},[],2)%minimum grade for each student in one vector and the index for the quiz in another
%% Part D
for x=[1:14]
fprintf('<%s>(%d)will drop grade(%s)from grade(%s)',(grade_Book{1}{:}),(grade_Book{2}(:)),(grade_Book{3}{:}),I)
end
I'm trying to have it to say <student name> (student ID) will drop (grade) from quiz (indexed quiz number)
Thank you for your help in advance!
2 commentaires
Réponse acceptée
Stephen23
le 22 Fév 2021
%% Part A
S = load('QuizGrades.mat');
grades = S.grades
student_Names = "Student"+(1:14)
student_IDs = 101:114;
%% Part B
mean(grades(3,:))% mean of the quiz grades for student 3
mean(grades(:,5))% mean of student grades on quiz 5
mean(grades)% mean of grades for all quizzes
%% Part C
[M,I] = min(grades,[],2); %minimum grade for each student in one vector and the index for the quiz in another
%% Part D
fmt = '<%s>(%d)will drop grade(%d)from quiz(%d)\n';
for k = 1:14
fprintf(fmt,student_Names(k),student_IDs(k),M(k),I(k))
end
Or avoiding the loop:
tmp = [cellstr(student_Names);num2cell([student_IDs(:),M,I]).'];
fprintf(fmt,tmp{:})
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Whos dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!