How to calculate the "Fit to estimation data validation" and the "MSE" between 2 curves and add it to the legend of the graphic?

13 ビュー (過去 30 日間)
Miguel 2023 年 3 月 19 日
回答済み: Nikhilesh 2023 年 3 月 31 日
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
denM=[1 0.1912];
M=tf(numM,denM, 'Outputdelay',0.02);
for f=[0.3 0.5 0.7 0.1]
hold all
for x=[0.3 0.5 0.7 0.1]
opt = stepDataOptions;
opt.StepAmplitude =x;
hold all
hold off
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;

回答 (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 ( 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 ( and sum. Finally you can plot the fit curve with the legend using sprintf.


Help Center および File ExchangeInterpolation についてさらに検索




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by