How to store values from a loop in a matrix

2 ビュー (過去 30 日間)
Jonathon
Jonathon 2012 年 9 月 17 日
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.

回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2012 年 9 月 17 日
編集済み: Andrei Bobrov 2012 年 9 月 17 日
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

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by