How to save output in array

11 次查看(过去 30 天)
Emily
Emily 2022-5-31
回答: Voss 2022-5-31
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)]

采纳的回答

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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by