# Anyone know what is wrong with my T2* calculations?

5 views (last 30 days)
William on 23 Mar 2023
Commented: William on 4 Apr 2023
%Variable definitions:
%T2* Calculations, lets see if this works
fitfunc = cftool;
%Echo times matrix
x = [0.086883, 0.15, 0.3, 0.7 ];
%Images = matrix;
Images = zeros(128,128,128,4);
Images = Images/max(Images(:));
%%
tic
SB=0;
%f0 = fitoptions('Origins',[0,0]);
for i = 1:128
for j = 1:128
parfor k = 1:128
try
y = squeeze(Images(i,j,k,:));
%myfit = fit(x',y,'exp2','StartPoint',[0,0,0,0]);
myfit = fit(x',y, 'a*exp(-x/b)+c', 'StartPoint', [1,0.2,0.001],'UpperLimit',[10000,2,.05],'LowerLimit',[0,0,-Inf]);
A(i,j,k) = myfit.a;
B(i,j,k) = myfit.b;
C(i,j,k) = myfit.c;
%D(i,j,k) = myfit.d;
catch
%B(i,j,k) = -10;
%disp('Something Broke');
SB=SB+1;
end
end
end
end
end
toc
So when I try to run the mask (Gated_ImageTE1_1.nii.gz) over the origianl scan ('Original_Gated_Image_TE1_1.nii.gz') nothing comes back. When I unkill the catch functions the entire thing just ends up having a value of -10 where the mask should be. So I am unsure as to what is happening and why. If anyone could let me know what is happening that would be greatly appreciated! Thanks in advance.

Catalytic on 23 Mar 2023
Edited: Catalytic on 23 Mar 2023
The problem with try...catch is that if you have any coding errors in the try block, it will never get executed. Here, you are using parameter names 'UpperLimit' and 'LowerLimit', which do not exist.
It would be much better to request an exitflag from FIT, instead of using try/catch -
[myfit,~,output]=fit( ___ )
if output.exitflag<=0
continue
end
William on 4 Apr 2023
This helped! Sorry it took me a while to get back to you. Forgot to respond and mark helped