How to save output in array

17 ビュー (過去 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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by