display functions and coefficients from the basic fit tool box on a plot

6 ビュー (過去 30 日間)
Jamie Williamson
Jamie Williamson 2021 年 9 月 15 日
コメント済み: Chunru 2021 年 9 月 15 日
Is there away to show basic fitting on a plot whenever the code is run? rather then going to tools > basic fitting and manually doing it everytime?? I want to show the function and coeffecients on a plot everytime the code is run and the plots are produced

回答 (2 件)

Chunru
Chunru 2021 年 9 月 15 日
編集済み: Chunru 2021 年 9 月 15 日
Use your own fitting function:
% Some data
x = 0:.1:10;
y = x.^2 +2*x + 3 +randn(size(x))*.4;
plot(x, y)
% fitting (polyfit of order of 2)
p = polyfit(x, y, 2)
p = 1×3
1.0135 1.8552 3.2872
% Plot the fitting result
hold on
plot(x, polyval(p, x), 'r--')
  1 件のコメント
Jamie Williamson
Jamie Williamson 2021 年 9 月 15 日
Iv got some data points and three fuctions I want to plot with a curve fit and also have the functions printed on the graphs. is this possible??
Data Functions
x y y = 0.6580x-1.337209
3.25 0.801369 y = 0.0632e^0.7817x
3.375 0.883622 y = 0.0379x^2.5890

サインインしてコメントする。


Chunru
Chunru 2021 年 9 月 15 日
編集済み: Chunru 2021 年 9 月 15 日
xy = [3.25 0.801369;
3.375 0.883622];
x = xy(:, 1);
y = xy(:, 2);
f1 = @(x) 0.6580*x-1.337209;
f2 = @(x) 0.0632*exp(0.7817*x);
f3 = @(x) 0.0379*x.^2.5890;
f1str = char(f1);
f2str = char(f2);
f3str = char(f3);
plot(x, y, 'b');
hold on
fplot(f1, x([1 end])', 'g');
fplot(f2, x([1 end])', 'k');
fplot(f3, x([1 end])', 'r');
legend({'Data', f1str(5:end), f2str(5:end), f3str(5:end)}, 'Location', 'Best')

カテゴリ

Help Center および File ExchangeGet Started with Curve Fitting Toolbox についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by