How to store values from a loop in a matrix
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
So I'm still bumbling around MATLAB. Basically I have this for loop taht does what I want but I want it to store the values in a matrix named M3:
for ii = 1:length(M)
X = M(ii,2);
if X<60
y = 'F';
elseif X>=60 & X<70
y = 'D';
elseif X>=70 & X<80
y = 'C';
elseif X>=80 & X<90
y = 'B';
else
y = 'A';
end
GR(ii) = y;
end
GR.'
How does one set it to store it in a 1 column, 6 row matrix named M3.
0 commentaires
Réponses (1)
Andrei Bobrov
le 17 Sep 2012
Modifié(e) : Andrei Bobrov
le 17 Sep 2012
M3 = cell(size(M,1),1);
for ii = 1:size(M,1)
X = M(ii,2);
if X<60
M3{ii} = 'F';
elseif X>=60 & X<70
M3{ii}= 'D';
elseif X>=70 & X<80
M3{ii} = 'C';
elseif X>=80 & X<90
M3{ii} = 'B';
else
M3{ii} = 'A';
end
end
0 commentaires
Voir également
Catégories
En savoir plus sur Characters and Strings 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!