index exceed matrix dimension error
显示 更早的评论
hello this is my code and when i run it i get the error index exceed matrix dimension. i cant figure out the error so anyone can help?
[m,n]=size(I0);
M=0.5*ones(4,3);
M(1,2)=0.5*cos(2*0);
M(1,3)=0.5*sin(2*0);
M(2,2)=0.5*cos(2*0.61);
M(2,3)=0.5*sin(2*0.61);
M(3,2)=0.5*cos(2*1.57);
M(3,3)=0.5*sin(2*1.57);
M(4,2)=0.5*cos(2*2.71);
M(4,3)=0.5*sin(2*2.71);
M=double(M);
%reconstruction surface
S0=zeros(m,n);
S1=zeros(m,n);
S2=zeros(m,n);
S3=zeros(m,n);
disp('calculate stokes')
for i=1:m
for j=1:n
I=double([I0(i,j);I35(i,j);I90(i,j);I155(i,j)]);
S=linsolve(M,I);
S0(i,j)=S(1,1);
S1(i,j)=S(2,1);
S2(i,j)=S(3,1);
end
end
ro=sqrt(S1.*S1+S2.*S2)./(S0+eps);
AzimuthalAngle=0.5*atan(S2./(S1+eps));
disp('mask')
MASQUE=OuvreMasque_2011('masque.png',I0) %imread('masque 1629.jpg');
MASQUE=im2bw(MASQUE);
%contourf(ro.*MASQUE);
disp('rho, phi')
ro=min(abs(ro),0.90);
ZenithalAngle=zeros(m,n);
nc=8;
options=optimset('Display','notify');
kc=fsolve(@(t)(2*nc*(1/(1+2*nc+nc^2+t^2)+1/(nc^2+t^2+2*nc+1))-0.37),1,options);
count=m*n;
for i=1:m
for j=1:n
* _if MASQUE(i,j)==1_ *
ZenithalAngle(i,j)=fsolve(@(t)((nc^2+kc^2-1)*(1-cos(t)^2)/((nc^2+kc^2+1)*(1+cos(t)^2)+4*nc*cos(t))-ro(i,j)),0.5,options);
end
count=count-1;
end
end
it is stated that the error is 'if MASQUE(i,j)==1'.
5 个评论
dpb
2014-5-21
What is
size(MASQUE)
and
m, n
at that point?
doc debug
on setting breakpoint and using the debugger to sort out such problems.
As a general rule, copy and paste the full text of the error in context of the code rather than just paraphrasing a small portion of it.
Image Analyst
2014-5-22
You forgot to include your error message ( all the red text) you just snipped out a small, nearly useless part of the error message. Also, please look at this, which will solve your problem for you: http://blogs.mathworks.com/videos/2012/07/03/debugging-in-matlab/
bourgogne
2014-5-22
dpb
2014-5-22
...the size at that point is 308,236. the size is not fixed as the code prompt user to crop image to get the cropped size.
And what were/are m and n? Doesn't look like you update them anywhere to match this cropped (reduced) image size. Again, use the debugger...
bourgogne
2014-5-22
回答(1 个)
Sean de Wolski
2014-5-22
dbstop if error
Will stop when the error occurs so you can inspect every variable at the time of the error. It should then be obvious what is exceeding the size.
类别
在 帮助中心 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!