Matlab loop closes for no reason at all

1 visualización (últimos 30 días)
berk can acikgoz
berk can acikgoz el 13 de Sept. de 2020
Comentada: Image Analyst el 13 de Sept. de 2020
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 comentarios
VBBV
VBBV el 13 de Sept. de 2020
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 el 13 de Sept. de 2020
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.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by