フィルターのクリア

Index in position 2 exceeds array bounds

2 ビュー (過去 30 日間)
Fernanda Vanessa Almendarez Juarez
Fernanda Vanessa Almendarez Juarez 2020 年 2 月 18 日
回答済み: Hyeokjin Jho 2020 年 2 月 18 日
I have a problem with this, I dont know whats wrong
n=4;
r= 0.012;
pos = [0 0; 0 0.5; 0.5 0.5; 0.5 0]
a = zeros(1,n)
i=1
while( i<=n)
for(j=1:1:n-1)
for(k=1:1:n-1)
x = pos(k+1,1)-pos(1,j) %%------> I have the problem here
It says "Index in position 2 exceeds array bounds"

回答 (2 件)

KSSV
KSSV 2020 年 2 月 18 日
You size of pos is 4x2....you are trying to accessing third coulmn from pos....where as it has only two columns..so obviously you will end up with error.

Hyeokjin Jho
Hyeokjin Jho 2020 年 2 月 18 日
Since n = 4, for(j=1:1:n-1) will make j from 1 to 3.
However pos is 4x2 matrix. When j is 3, pos(1,j) refers outside of the matrix boundary.

カテゴリ

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