Display equation of exponential fitted line using fit function
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Daniel Jordan
am 8 Mär. 2022
Kommentiert: Davide Masiello
am 10 Mär. 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 Kommentare
Akzeptierte Antwort
Davide Masiello
am 8 Mär. 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 Kommentare
Walter Roberson
am 10 Mär. 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
am 10 Mär. 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
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Get Started with Curve Fitting Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!