How to write code for moments?

3 ビュー (過去 30 日間)
Sachin
Sachin 2013 年 3 月 20 日
How to write code for moments i.e 0th order(M00),1st order (M10,M01), i wrote it by using for loop
for i=0:1:1
for j=0:1:1
for k=1:1:row
for l=1:1:col
M(i,j)=M(i,j)+(k^i*l^j*I2(k,l));
end
end
end
end
but it gives error ??? Attempted to access M(0,0); index must be a positive integer or logical. is there any other way of writing code for Moments???

採用された回答

the cyclist
the cyclist 2013 年 3 月 20 日
編集済み: the cyclist 2013 年 3 月 20 日
MATLAB arrays are 1-based and not 0-based.
One solution is to just bump each index i and j by one for array storage purposes:
for i=0:1:1
for j=0:1:1
for k=1:1:row
for l=1:1:col
M(i+1,j+1)=M(i+1,j+1)+(k^i*l^j*I2(k,l));
end
end
end
end
Notice that my only change to your code was to replace M(i,j) with M(i+1,j+1).
  1 件のコメント
Sachin
Sachin 2013 年 3 月 22 日
thnx a lot

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by