1D interpolation by y = ax+b

16 次查看(过去 30 天)
Jaroslav Zadnik
Jaroslav Zadnik 2021-2-27
I have x and y data. I need interpolate (fit) data by y = a*x + b

回答(1 个)

Star Strider
Star Strider 2021-2-27
To set the start point at the origin (0,0), calculate the slope as:
slope = x(:) \ y(:);
for example:
x = 0:0.1:10;
y = rand(size(x));
slope = x(:) \ y(:);
figure
plot(x, y, '.b')
hold on
plot(x, slope*x, '--r')
hold off
grid
xlabel('x')
ylabel('y')
.
  6 个评论
Jaroslav Zadnik
Jaroslav Zadnik 2021-2-27
I would like to write it like this:
F1 = fit(x(1,:)',y','0.5+0.5*cos(2*pi*x/96-delta)','lower',[0],'upper',[2*pi],'startpoint',[pi]);
where I can write the equation directly
Star Strider
Star Strider 2021-2-27
I do not have the Curve Fitting Toolbox (since I do not need it for what I do in my research). This requirement was not implied or stated in the original Question you posted.
Without your data, I cannot code a similar function using the Statistics and Machine Learning Toolbox or the Optimization Toolbox functions, both of which I have and frequently use. I would need more information to provide an appropriate response.

请先登录,再进行评论。

类别

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