How to linearly fit a semilog graph

27 次查看(过去 30 天)
Hello
I have my data file which is attached below. I have to plot this as semilog ( log scale on Y-axis) and have to linearly fit like the image attached. Please help me with the same

回答(2 个)

Jonas
Jonas 2021-2-19

Star Strider
Star Strider 2021-2-26
Try this:
D1 = readmatrix('Data.xlsx');
x = D1(:,1);
y = D1(:,2);
[ymax,idx] = max(y);
idxrng = idx:numel(y);
objfcn = @(b,x,minlim) b(1).*exp(b(2).*x) + minlim;
B = fminsearch(@(b) norm(y(idxrng) - objfcn(b,x(idxrng),y(end))), [ymax; rand]);
figure
plot(x, y)
hold on
plot(x(idxrng), objfcn(B,x(idxrng),y(end)), '-r', 'LineWidth',1.5)
hold off
grid
set(gca, 'YScale','log')
It’s not easy to fit those data.
Using:
idxrng = 1:numel(y);
objfcn = @(b,x,minlim) b(1).*x.*exp(b(2).*x) + minlim;
instead, might be more accurate.
  4 个评论

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Graphics Object Identification 的更多信息

标签

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by