Azzera filtri
Azzera filtri

storing loop values in a matrix

1 visualizzazione (ultimi 30 giorni)
Danish Nasir
Danish Nasir il 25 Lug 2021
Commentato: Danish Nasir il 25 Lug 2021
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.

Risposta accettata

Walter Roberson
Walter Roberson il 25 Lug 2021
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)

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Tag

Prodotti


Release

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by