Effacer les filtres
Effacer les filtres

How to save output in array

10 vues (au cours des 30 derniers jours)
Emily
Emily le 31 Mai 2022
Réponse apportée : Voss le 31 Mai 2022
Hi, I'm trying to create a loop that prints the output in an array and not sure how to save/print as I want.
num=5;
for k=1:num
a=k^2;
num=num+1;
end
output=[a(1), a(2), a(3), a(4), a(5)]

Réponse acceptée

Voss
Voss le 31 Mai 2022
Like this?
num = 5;
for k = 1:num
a(k) = k^2;
end
disp(a)
1 4 9 16 25

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by