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

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
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/
below is the error message i get. 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.
??? Index exceeds matrix dimensions.
Error in ==> Topo at 58
if MASQUE(i,j)==1
Error in ==> kek_13_5_2014>pushbutton2_Callback at 212
Topo(handles);
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> kek_13_5_2014 at 21
gui_mainfcn(gui_State, varargin{:});
Error in ==>
@(hObject,eventdata)kek_13_5_2014('pushbutton2_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback
dpb
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
bourgogne 2014년 5월 22일
alright thanks very much i will try to use the debugger and see.

댓글을 달려면 로그인하십시오.

답변 (1개)

Sean de Wolski
Sean de Wolski 2014년 5월 22일

0 개 추천

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에 대해 자세히 알아보기

질문:

2014년 5월 21일

답변:

2014년 5월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by