storing loop values in a matrix

3 ビュー (過去 30 日間)
Danish Nasir
Danish Nasir 2021 年 7 月 25 日
コメント済み: Danish Nasir 2021 年 7 月 25 日
I have a column 10x1. Now i have to perform loop operation 5 times (i=1:5). I want to save the results of each loop so that the final matrix should be 10x5. Pls suggest the code.

採用された回答

Walter Roberson
Walter Roberson 2021 年 7 月 25 日
N = 10;
iters = 5;
column = randi(9,N,1)
column = 10×1
8 3 2 8 5 6 2 7 3 4
results_of_loop = zeros(N, iters);
for K = 1 : iters
results_of_loop(:,K) = column.^K / factorial(K);
end
results_of_loop
results_of_loop = 10×5
8.0000 32.0000 85.3333 170.6667 273.0667 3.0000 4.5000 4.5000 3.3750 2.0250 2.0000 2.0000 1.3333 0.6667 0.2667 8.0000 32.0000 85.3333 170.6667 273.0667 5.0000 12.5000 20.8333 26.0417 26.0417 6.0000 18.0000 36.0000 54.0000 64.8000 2.0000 2.0000 1.3333 0.6667 0.2667 7.0000 24.5000 57.1667 100.0417 140.0583 3.0000 4.5000 4.5000 3.3750 2.0250 4.0000 8.0000 10.6667 10.6667 8.5333
surf(results_of_loop)
  1 件のコメント
Danish Nasir
Danish Nasir 2021 年 7 月 25 日
Thanx...

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by