Display equation of exponential fitted line using fit function
6 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Davide Masiello
2022 年 3 月 8 日
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 件のコメント
Walter Roberson
2022 年 3 月 10 日
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
2022 年 3 月 10 日
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
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Get Started with Curve Fitting Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!