How to store values from a loop in a matrix
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Andrei Bobrov
el 17 de Sept. de 2012
Editada: Andrei Bobrov
el 17 de Sept. de 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 comentarios
Ver también
Categorías
Más información sobre Characters and Strings en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!