Matlab loop closes for no reason at all

조회 수: 1 (최근 30일)
berk can acikgoz
berk can acikgoz 2020년 9월 13일
댓글: Image Analyst 2020년 9월 13일
I have a loop as follows:
g=zeros(dim,dim);
for np=1:dim
b=2*pxHz*phantom(dim);b=b(:,np);
b=dct(b);
g(:,np)=dctCoeffs1d*dctGradVect(b,np);
np
end
figure, imagesc(g),colorbar
and dctGradVect function is as follows:
function g = dctGradVect(b,np)
global imgg imgDistupg imgDistdowng dctCoeffs1d
imgVect=imgg(:,np);distUpVect=imgDistupg(:,np);distDownVect=imgDistdowng(:,np);
fieldVect=dctCoeffs1d*b;
[Ku,Kd]=Kv(fieldVect);
[Ku2,Kd2]=Kv2(fieldVect);
for p=1:length(b)
for mp=1:length(imgVect)
matu(p,mp)=trace(diag(dctCoeffs1d(:,p)).*diag(Ku2(mp,:)).*diag(imgVect));
matd(p,mp)=trace(diag(dctCoeffs1d(:,p)).*diag(Kd2(mp,:)).*diag(imgVect));
end
end
g=2*real(matu*conj(distUpVect-Ku*imgVect))+2*real(matd*conj(distDownVect-Kd*imgVect));
The loop crashes at some values of np. i.e. crashes at np=10. This crashing point changes every time. Also it gives an error message, some index exceeding some value. However, for a number of iterations this is not the case. What could be the proble? Thx in advance
Edit: imgg, imgDistupg and imgDistdowng are complex dim by dim matrices. dim is fixed and 32 for my case. dctCoeffs1d is a dim by dim matrix again and represents 1d discrete cosine transform.
Edit 2: The loop works fine at first. I mean g is calculated and everything is ok. However, if I run the loop again, it get stuck and MATLAB crashes
  댓글 수: 4
VBBV
VBBV 2020년 9월 13일
What is dim when you create
%if true
% code
%end
g = zeros(dim,dim)
Is it fixed value or changing ?
May be it's exceeding the limit of one of the vectors in your function
%if true
% code
%end
function g = dctGradvect(b,np)
Image Analyst
Image Analyst 2020년 9월 13일
Looks like you blew right past the posting guidelines that would have enabled a fast answer. Anyway, give us code where we can reproduce it. This means ALL code, even the code that defined the global variables. Also, give the exact error message - ALL THE RED TEXT - but only after you read this link.

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by