Display equation of exponential fitted line using fit function

6 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Davide Masiello
Davide Masiello el 8 de Mzo. de 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 comentarios
Walter Roberson
Walter Roberson el 10 de Mzo. de 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
Davide Masiello el 10 de Mzo. de 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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Get Started with Curve Fitting Toolbox en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by