Hi i attached simple code,i need to store every result from for loop on each iteration,please see my code and alter it sir.

1 回表示 (過去 30 日間)
t=[1 2 3 4 5];
for i=1:4
for j=1:5
g=i+j;
l=max(g); %Here i need to save l value in one array,likewise save l value for all iteration
end
end
  3 件のコメント
Walter Roberson
Walter Roberson 2015 年 8 月 26 日
g is going to be a scalar. What is the point of using max() on the scalar?
kaavya subramani
kaavya subramani 2015 年 8 月 26 日
yes sir,g is scalar.in ist iteration i=1 is added with j=1:5.so result is 2,3,4,5,6.i need to rerieve max value(i.e)6.whereas in next iteration i=2 and j=1:5,so result is 3,4,5,6,7.so i need to save max value (i.e) 7.likewise i need to save all the max value in all iteration in array

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2015 年 8 月 27 日
nt = length(t);
for i = 1:4
g = zeros(nt,1);
for j = 1:nt
g(j) = i + t(j);
end
l(i) = max(g);
end
or more simply
for i = 1 : 4
g = i + t;
l(i) = max(g);
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by