How to solve "Index exceeds matrix dimensions" error?
Ä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 an element in column 6 is zero. In doing so, I run the following command.
load filename.txt;
for i = 1:length(filename)
if filename(i,6) = 0;
filename(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.
Akzeptierte Antwort
Weitere Antworten (2)
Oleg Komarov
am 20 Feb. 2012
1 Stimme
Because you're shrinking filename if the condition is verified.
Once you delete a row, the length of filename is one unit smaller but the loop is still setup from 1 to initial dimension of filename.
nfllover
am 20 Feb. 2012
0 Stimmen
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!