How can I return the values of a loop
古いコメントを表示
I want to return the entire values of k matrice but I only end up with values from the last row.
for i = 1:5,
j = 0:i;
k = i.^2 + i*j + j.^2
end
採用された回答
その他の回答 (1 件)
Andrei Bobrov
2016 年 5 月 12 日
編集済み: Andrei Bobrov
2016 年 5 月 12 日
n = 5;
k = tril(((1:n)'*ones(1,n+1)).^2+(1:n)'*(0:n)+(ones(n,1)*(0:n)).^2,1);
with for..end loop
n = 5;
k = zeros(n,n+1);
for ii = 1:5,
jj = 0:ii;
k(ii,1:ii+1) = ii.^2 + ii*jj + jj.^2;
end
2 件のコメント
zaxtronix
2016 年 5 月 13 日
Andrei Bobrov
2016 年 5 月 13 日
hm...
[ii,jj] = ndgrid(1:5,0:5);
k = ii.^2 + ii.*jj + jj.^2;
カテゴリ
ヘルプ センター および File Exchange で Operators and Elementary Operations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!