Index exceeds matrix dimentions
Ältere Kommentare anzeigen
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,:)=[];
3 Kommentare
@pamela sulis: please stop posting duplicate questions. So far you have posted the same basic question at least three times. Doing so actually makes our work harder as to keep track of what you are writing and what answers you have been given. I closed the other questions.
Instead of creating duplicates you can simply edit your question or add a comment to it (note: do not add an answer unless it really is an answer).
Eng. Fredius Magige
am 27 Okt. 2015
Bearbeitet: Eng. Fredius Magige
am 27 Okt. 2015
Hi try this if(~all(StayCell(:,2:7))) instead of if(StayCell(:,2:7)==0)
pamela sulis
am 27 Okt. 2015
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Matrix Indexing finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!