How to calculate the "Fit to estimation data validation" and the "MSE" between 2 curves and add it to the legend of the graphic?
14 次查看(过去 30 天)
显示 更早的评论
I have 2 types of plots that, in the end, hold all and the matlab returns a graphic with 8 curves. However there are 4 pars of curves that i want to know the fit data estimation and the MSE (each par is form by a "--" and "-" curve). Knowing those 2 parameters i want tha they apperar in front of the four last legnd topics like this: M(0.3) Fit:... MSE:...
%Função de transferência do par xF-xP
numM=[1.123];
denM=[1 0.1912];
M=tf(numM,denM, 'Outputdelay',0.02);
hfig=figure;
for f=[0.3 0.5 0.7 0.1]
sim("Evaporador_18_03_2023.slx");
plot(t,xP_d,'--','LineWidth',2.5);
hold all
end
for x=[0.3 0.5 0.7 0.1]
opt = stepDataOptions;
opt.StepAmplitude =x;
[y,p]=step(M,40,opt);
plot(p,y,'LineWidth',1);
hold all
end
hold off
grid;
title('Comparação....'); %colocar um melhor título
xlabel('Tempo (horas)')
ylabel('% weight');
legend('xF vs xP(0.3)','xF vs xP(0.5)','xF vs xP(0.7)','xF vs xP(0.1)','M(0.3)','M(0.5)','M(0.7)','M(0.1)');
ax = gca;
colororder(["#2477B5";"#E90824";"#000000";"#A2142F";"#E68000";"#26D254";"#BBB81D";"#4580EE"]);
0 个评论
回答(1 个)
Nikhilesh
2023-3-31
Hi Miguel,
To add the fit data estimation and the MSE to the legend for each pair of curves, you can use the fit function (Fit curve or surface to data - MATLAB fit (mathworks.com)) to fit a curve to the data and then extract the fit data and the MSE.
You can use a loop to iterate through each pair of curves and fit a curve to the data using fit. Then you can extract the fit data and the MSE using func2str (Construct character vector from function handle - MATLAB func2str (mathworks.com)) and sum. Finally you can plot the fit curve with the legend using sprintf.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!