Display equation of exponential fitted line using fit function
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Daniel Jordan
le 8 Mar 2022
Commenté : Davide Masiello
le 10 Mar 2022
Here's my code, I want to find the equation of the fitted line on either of the figures.
clc
clear
T = readtable('ViscosityResults.xlsx','Range','L2:M14',... #read spreadsheet and select range
'ReadVariableNames',true,'VariableNamingRule','preserve')... #take headings from file and keep them as they are
figure; %experimental results
x = T{:,1}
y = T{:,2}
f = fit(x,y,'exp1'); %create variables
plot(f,x,y)
xlim([0,40])
ylim([0,40])
title('Viscosity of ED1242-9001 primer by % volume water','(experimental results)')
xlabel('% Volume water')
ylabel('Viscosity (cP)') %plot and format graph
grid on
figure; %forecast graph
xx=linspace(0,80,500);
plot(xx,f(xx))
xlim([0,80])
ylim([0,40])
title('Viscosity of ED1242-9001 primer by % volume water')
xlabel('% Volume water')
ylabel('Viscosity (cP)') %plot and format graph
grid on
0 commentaires
Réponse acceptée
Davide Masiello
le 8 Mar 2022
See if this works
clc
clear
T = readtable('ViscosityResults.xlsx','Range','L2:M14',... #read spreadsheet and select range
'ReadVariableNames',true,'VariableNamingRule','preserve')... #take headings from file and keep them as they are
figure; %experimental results
x = T{:,1}
y = T{:,2}
f = fit(x,y,'exp1'); %create variables
txt = sprintf('f(x)=%.2f*exp(%.2f*x)\n',[f.a,f.b]);
plot(f,x,y)
xlim([0,40])
ylim([0,40])
title('Viscosity of ED1242-9001 primer by % volume water','(experimental results)')
xlabel('% Volume water')
ylabel('Viscosity (cP)') %plot and format graph
text(min(x),max(y),txt)
grid on
figure; %forecast graph
xx=linspace(0,80,500);
plot(xx,f(xx))
xlim([0,80])
ylim([0,40])
title('Viscosity of ED1242-9001 primer by % volume water')
xlabel('% Volume water')
ylabel('Viscosity (cP)') %plot and format graph
text(min(x),max(y),txt)
grid on
3 commentaires
Walter Roberson
le 10 Mar 2022
The equation is currently being displayed according to
text(min(x),max(y),txt)
so change the min(x) and max(y) to whatever values are appropriate for your purpose.
You might also want to consider instead using legend() to display the equation.
Davide Masiello
le 10 Mar 2022
Yes. The first two entries of the command text() are the coordinates where the top-left corner of the bounding box of the displayed text are placed.
For more info, I suggest you check this link
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!