index exceed matrix dimension error
조회 수: 1 (최근 30일)
이전 댓글 표시
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월 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...
답변 (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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!