problem with starting a loop for matrices

1 回表示 (過去 30 日間)
Hajar Alshaikh
Hajar Alshaikh 2023 年 2 月 16 日
回答済み: John D'Errico 2023 年 2 月 16 日
if i have algorithm start with X0, and Y0 as agiven matrices
then i want to start a loop should I write
for k=1: 30
Z(k)=f(X0,Y0)
or should i start a loop from k=0 and write it as
Z(k)=f(X(0),Y(0))
i want to ubdate the X and Y at each iteration

採用された回答

John D'Errico
John D'Errico 2023 年 2 月 16 日
MATLAB does not allow an index origin of zero. This means that the FIRST element in a vector, for example, is indexed at number 1. The zero'th element does not exist in a matrix, at least not in MATLAB. So, for example, if I do this:
x = zeros(1,5);
for i = 1:5
x(i) = i;
end
x
x = 1×5
1 2 3 4 5
x(1)
ans = 1
And as you can see, x(1) is that first element.

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