index exceeds matrix dimensions??
Afficher commentaires plus anciens
This is part of a loop that I'm trying to run and get an error:
c = zeros(1,20);
for b=1:20
a = 1;
while dH_df(a,b)<0.80 %line 199
a = a+1;
end
c(b) = a;
dH_df(c(b),b);
end
The error is:
"??? Index exceeds matrix dimensions.
Error in ==> filename at 199 while dH_df(a,b)<0.80"
-I tried a few things, but I still can't see where the error stems from A few clarifications: -this loop is part of a bigger program that calculates dH_df
-dH_df is a 31x20 matrix with values ranging from 0.4700 to 1.1100
-the loop is supposed to record the position of values ranging 0.80 to 0.85 from dH_df and record the row position in "c" - I'm having trouble setting up that range as well
Any suggestions will be really appreciated. Thank you.
Réponse acceptée
Plus de réponses (2)
Sean de Wolski
le 22 Juin 2011
does dH_df of that line have any values <0.8? If it doesn't 'a' will grow to be bigger than the matrix and it would throw that error.
You could replace the while loop with
[a,a] = max(dH_df>=0.80,[],2);
and it will find 'a' for each row all at once (assuming each row has a value less than 0.8, else it'll return the first column.)
Annie M
le 23 Juin 2011
Catégories
En savoir plus sur Matrix Indexing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!