How to store values from a loop in a matrix
2 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Andrei Bobrov
on 17 Sep 2012
Edited: Andrei Bobrov
on 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 Comments
See Also
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!