Index in position 1 is invalid error

3 ビュー (過去 30 日間)
Maaz Madha
Maaz Madha 2020 年 3 月 19 日
コメント済み: Fangjun Jiang 2020 年 3 月 19 日
n=(L/delta_x)+1;%%lecture notes 21/1/2020. Converts rectangle to a mesh
m=(H/delta_y)+1;
x=[0:delta_x:L]';
y=[0:delta_y:H]';
A=zeros(size(y,1),size(x,1));%%setting up the A matrix
A=meshgrid(x,y);
for i=n
for j=2:m-2
pointer(i,j)=(j-1)*n+i
end
end
everytime i run the for loop it says Index in position 1 is invalid. Array indices must be positive integers or logical values. I don't understand why this is happening and how to avoid it.

採用された回答

Fangjun Jiang
Fangjun Jiang 2020 年 3 月 19 日
before the loop, check the value of n and m. They might not be an integer. You are doing pointer(n,2) for the first loop.
  2 件のコメント
Maaz Madha
Maaz Madha 2020 年 3 月 19 日
I don't understand what you mean by pointer(n,2). Otherwise your advice to round my values really helped. Thanks
Fangjun Jiang
Fangjun Jiang 2020 年 3 月 19 日
based on your code, the first value assigned to the matrix pointer is pointer(n,2).
You might want to double-check your for-loop code.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by