index exceed matrix dimension error
Mostra commenti meno recenti
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 Commenti
dpb
il 21 Mag 2014
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
il 22 Mag 2014
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
il 22 Mag 2014
dpb
il 22 Mag 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
il 22 Mag 2014
Risposte (1)
Sean de Wolski
il 22 Mag 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.
Categorie
Scopri di più su Matrix Indexing in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!