Index exceeds matrix dimensions.

1 回表示 (過去 30 日間)
Locks
Locks 2013 年 4 月 10 日
hi,
I have used this code here:
for i=1:length(data8(:,1))
if(data8(i,8)>1.1)
data8(i,:) = [];
end
if(data8(i,8)<0.9)
data8(i,:) = [];
end
end
where data 8 is a matrix with 8 columns, and I get this error message:
Index exceeds matrix dimensions.
Error in construct_data (line 43) if(data8(i,8)>1.1)
has anybody an idea why this can happen?

採用された回答

Cedric
Cedric 2013 年 4 月 10 日
編集済み: Cedric 2013 年 4 月 10 日
length(data8(:,1))
is evaluated only once at the beginning of the FOR loop. It is e.g. 10. Then you remove rows from data8 , whose size therefore decreases (9 rows, 8 rows, ..). At one point the loop index (that is still incremented until it hits 10) becomes larger than the remaining number of rows in data8.
  3 件のコメント
Cedric
Cedric 2013 年 4 月 10 日
編集済み: Cedric 2013 年 4 月 10 日
Several ways, one is:
i = 0 ;
while i < size(data8, 1)
i = i + 1 ;
% .. whatever you have to do.
end
Locks
Locks 2013 年 4 月 10 日
great, thanks!

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

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