index exceeds matrix dimensions??
이전 댓글 표시
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.
채택된 답변
추가 답변 (2개)
Sean de Wolski
2011년 6월 22일
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.)
카테고리
도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!