Info

この質問は閉じられています。 編集または回答するには再度開いてください。

How to solve "Index exceeds matrix dimensions" error?

1 回表示 (過去 30 日間)
pamela sulis
pamela sulis 2015 年 10 月 27 日
閉鎖済み: Stephen23 2015 年 10 月 27 日
My question might be simple for most of you. Basically, I would like to delete a row of a matrix where a value of the elements in columns from 2 to 7 is zero. In doing so, I run the following command.
for i=1:size(StayCell,1)
if StayCell(i,2:7)==0
StayCell(i,:)=[];
end
end
However, the error message comes up saying that "Index exceeds matrix dimensions.". I don't understand why it exceeds the dimension because I have already specified that i = 1 to the length of the matrix. Any help on this would be appreciated. Thank you.
I try also this codes but i have the same problems
for i=length(StayCell)
if(StayCell(:,2:7)==0)
StayCell(i,:)=[];
end
end
StayCell(StayCell(:,2:7)==0,:)=[];

採用された回答

Eng. Fredius Magige
Eng. Fredius Magige 2015 年 10 月 27 日
Hi It might need to recalling as ready reduced the row, thus try this:
StayCell=StayCell for i=1:size(StayCell,1) if StayCell(i,2:7)==0 StayCell(i,:)=[]; end StayCell=(StayCell, [ ]) end
  1 件のコメント
pamela sulis
pamela sulis 2015 年 10 月 27 日
I have the same problem... and StayCell=(StayCell, [ ]) create an error :(

その他の回答 (0 件)

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by