Anyone know what is wrong with my T2* calculations?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
%Variable definitions:
Masks = niftiread("Gated_Image_TE1_1.nii.gz");
%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(:,:,:,1) = niftiread('Original_Gated_Image_TE1_1.nii.gz');
Images(:,:,:,2) = niftiread('Original_Gated_Image_TE2_1.nii.gz');
Images(:,:,:,3) = niftiread('Original_Gated_Image_TE3_1.nii.gz');
Images(:,:,:,4) = niftiread('Original_Gated_Image_TE4_1.nii.gz');
Images = Images/max(Images(:));
%%
tic
A = zeros(size(Masks));
B = zeros(size(Masks));
C = zeros(size(Masks));
D = zeros(size(Masks));
SB=0;
%f0 = fitoptions('Origins',[0,0]);
for i = 1:128
for j = 1:128
parfor k = 1:128
if Masks(i,j,k) == 1
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.
0 commentaires
Réponse acceptée
Catalytic
le 23 Mar 2023
Modifié(e) : Catalytic
le 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
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!