index exceed matrix dimension error

1 view (last 30 days)
bourgogne
bourgogne on 21 May 2014
Answered: Sean de Wolski on 22 May 2014
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 Comments
dpb
dpb on 22 May 2014
...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
bourgogne on 22 May 2014
alright thanks very much i will try to use the debugger and see.

Sign in to comment.

Answers (1)

Sean de Wolski
Sean de Wolski on 22 May 2014
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.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!