A simple for loop question

10 ビュー (過去 30 日間)
Ulrich Achas
Ulrich Achas 2021 年 5 月 9 日
コメント済み: Ulrich Achas 2021 年 5 月 9 日
isb=6;
for i=1:3
nta=(1+isb).^2/isb
isb=nta;
end
Hello everyone. I have just started to use MATLAB and I wrote the code above. My question is: When I ran this code, MATLAB gave me only last value of nta. But I need all nta values as an matrix. How can I write it? Thanks.
  2 件のコメント
Jonas
Jonas 2021 年 5 月 9 日
use nta(i) in both cases
Ulrich Achas
Ulrich Achas 2021 年 5 月 9 日
thank you.

サインインしてコメントする。

採用された回答

Mazdack Ameri
Mazdack Ameri 2021 年 5 月 9 日
編集済み: Mazdack Ameri 2021 年 5 月 9 日
you could do something like this:
isb=6;
nta_matrix = zeros(3,1); %initializing, it usually saves memory.
for i=1:3
nta_matrix(i) = (1+isb).^2/isb;
isb=nta_matrix(i);
end
  1 件のコメント
Ulrich Achas
Ulrich Achas 2021 年 5 月 9 日
it worked, thank you so much.

サインインしてコメントする。

その他の回答 (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