필터 지우기
필터 지우기

How to use exponential function to fit my data?

조회 수: 2 (최근 30일)
Taoooooooooooo
Taoooooooooooo 2021년 11월 3일
댓글: Mathieu NOE 2021년 11월 19일
Hi,
I tried to use lsqcurvefit function to fit my data and the results did not look right at all. The x and y are attached above where y is the center_voxel (80-by-1Matrix). Please help and here is my code:
x = linspace(0,128,80);
y = center_voxel';
xdata=x;
ydata=y;
lb = [-100, -100, -100];
ub = [100, 100, 100];
fun = @(xx,xdata)xx(1).*exp(xx(2).*xdata)+xx(3);
x0 = [0.5, 0.5, 0.5];
xx = lsqcurvefit(fun,x0,xdata,ydata,ub,lb)
yy = linspace(xdata(1),xdata(end));
figure
plot(xdata, ydata, 'pg')
hold on
plot(yy, fun(xx,yy),'r-')

채택된 답변

Mathieu NOE
Mathieu NOE 2021년 11월 5일
hello
try this
clc
clearvars
load('x axis.mat')
load('y axis.mat')
x = linspace(0,128,80);
y = center_voxel';
f = @(a,b,c,x) a.*exp(x.*b)+c;
obj_fun = @(params) norm(f(params(1), params(2), params(3),x)-y);
sol = fminsearch(obj_fun, [-y(end),-1e-1,y(end)]);
a = sol(1)
b = sol(2)
c = sol(3)
figure;
plot(x, y, '+', 'MarkerSize', 10, 'LineWidth', 2)
hold on
plot(x, f(a, b,c, x), '-');grid on
xlabel('x');
ylabel('y');
a = -3.5863e+03
b = -0.0143
c = 3.4995e+03

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by