Calculating and printing uncertainties of fits after the "normal" display of fit-parameters
Afficher commentaires plus anciens
Hello,
I am storing multiple fits in a cell array "fits". Currently I am just using celldisp to obtain f.e. the following:
>> celldisp(fit)
fit{1} =
Linear model Poly1:
y(x) = p1*x + p2
Coefficients (with 95% confidence bounds):
p1 = 0.00226 (0.002015, 0.002506)
p2 = 0.004049 (0.003472, 0.004627)
fit{2} =
Linear model Poly1:
y(x) = p1*x + p2
Coefficients (with 95% confidence bounds):
p1 = 0.004422 (0.004302, 0.004542)
p2 = 0.003982 (0.0037, 0.004264)
Now I am trying to print the following instead to the command window:
Fit{1} = % What I would like to print instead
Linear model Poly1:
y(x) = p1*x + p2
Coefficients (with 95% confidence bounds):
p1 = 0.00226 (0.002015, 0.002506) +- 0.000246 % (values obtained by calculating upper bound - value outside brackets)
p2 = 0.004049 (0.003472, 0.004627) +- 0.000578 % (i.e 0.004627-0.004049=0.000578 and so on)
Fit{2} =
Linear model Poly1:
y(x) = p1*x + p2
Coefficients (with 95% confidence bounds):
p1 = 0.004422 (0.004302, 0.004542) +- 0.00012
p2 = 0.003982 (0.0037, 0.004264) +- 0.000282
My first idea was to then extract the values from the different fits:
for j=1:1:numel(fit)
% Extract All Data:
Coeffvalues{j}=coeffvalues(fit{j}); % get the p1 and p2 values
Confintvalues{j}=confint(fit{j}); % get the corresponding confidence bounds
end
for j=1:1:numel(Coeffvalues)
Confintcalcvals=Confintvalues{j}(2,:)';
for k=1:1:length(Coeffvalues{1,1})
Difference(j,k)= Confintcalcvals(k)-Coeffvalues{1,j}(k); % Row j contains the diffs for fit j, position k is for the respective value
end
end
Difference % contains the differences to be inserted into the displayed fit messages, one row per fit
Now I should have all data I need in nice sorted columns, one per parameter.
My problem now is that I have no clue whatsoever how to emulate the message given when fits are displayed, and then add these values at the correct positions. For instance, I couldn't figure out how to access the string of the cfit-object containing the fit equation, since I assume I would have to rebuild the entire message string by string, which I only now realise could become a pain in the ass if we have a differing number of Coefficients. No clue how to do that automatically aside from coding it for the first X possibilities and just hope you won't encounter a fit with more than X parameters. I assume this is not the best way.
This gets worse since I have to make the entire process loopable so it repeats for whatever number of fits I end up having.
Thank you & stay save.
C.A.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Linear Predictive Coding dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!