How to store values from a loop in a matrix

2 Ansichten (letzte 30 Tage)
Jonathon
Jonathon am 17 Sep. 2012
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.

Antworten (1)

Andrei Bobrov
Andrei Bobrov am 17 Sep. 2012
Bearbeitet: Andrei Bobrov am 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

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by