Using 'plotResiduals' in a for loop.. is it possible to using indexing to store the results and plot then together?
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
mel1708
le 9 Jan 2020
Réponse apportée : Chidvi Modala
le 30 Jan 2020
I have a series of data fits I've performed using 'fitnlm' which I've acquired using a for loop like so.
fittables = cell(1, numel(files));
modelfun = @(sigma,x) exp(-x.^2 / (2 * sigma));
for k = 1:length(files)
table{k} = table(x{k}, y{k}, 'VariableNames', {'x', 'y'});
beta0 = 1;
mdl{k} = fitnlm(table{k}, modelfun, beta0);
end
I want to use the 'plotResiduals()' function to plot the residuals of each of these fits onto one graph. I can get it to work on a single fit but I can't work out how to index the function. I've tried the following two ways..
residuals{k} = plotResiduals(mdl{k},'caseorder');
which will run but it just overwrites the plot with each iteration,
and
residuals(k) = plotResiduals(mdl(k),'caseorder');
which results in the error "Undefined function 'plotResiduals' for input arguments of type 'cell' ".
Is there any way to plot these residuals on the same plot within the for loop? Indexing doesn't seem to be working.
2 commentaires
Jakob B. Nielsen
le 9 Jan 2020
Do you have
hold on
active? It retains plots in the current axes, whereas if hold is off, plots are overwritten.
Réponse acceptée
Chidvi Modala
le 30 Jan 2020
It appears that plotResidual respects "hold on" for other than probability plots. You can create the probability plot directly using normplot, and not using probplot or plotResiduals. For example:
load carsmall
tbl = table(MPG,Weight);
tbl.Year = categorical(Model_Year);
mdl = fitlm(tbl,'MPG ~ Year + Weight^2');
normplot(mdl.Residuals.Raw);
hold on;
h1= plotResiduals(mdl)
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Get Started with Curve Fitting Toolbox dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!