How to use exponential function to fit my data?

5 visualizaciones (últimos 30 días)
Taoooooooooooo
Taoooooooooooo el 3 de Nov. de 2021
Comentada: Mathieu NOE el 19 de Nov. de 2021
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-')

Respuesta aceptada

Mathieu NOE
Mathieu NOE el 5 de Nov. de 2021
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

Más respuestas (0)

Categorías

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

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by