필터 지우기
필터 지우기

storing loop values in a matrix

조회 수: 1 (최근 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)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops 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