How can i use a defined variable in equation for fitting ?
显示 更早的评论
Hi, I have defined previous variable by calculation in matlab, and I want to use the result store in variables inside the equation use for fitting. Even by defining these variables as global, the fitting operation does not take in account the real value of these variable. For example :
temp = [320; 330; 340; 350];
prop = [427; 452; 503; 537];
b = 3;
ub = fit(temp, prop, 'a * x + b')
plot(temp,prop,'ro');
hold on;
plot(ub, temp, prop);
hold off;
this is giving me the following fit :
General model:
ub(x) = a * x + b
Coefficients (with 95% confidence bounds):
a = 3.81 (2.366, 5.254)
b = -796.6 (-1281, -312.4)
But I want "b" to be as defined previously : 3.
How can I use a defined variables inside the equation for fitting ?
Thanks.
回答(3 个)
Star Strider
2017-12-13
One option is to use an anonymous function:
b = 3;
f = @(a) a.*x + b;
To do a simple linear fit, you need only core MATLAB:
temp = [320; 330; 340; 350];
prop = [427; 452; 503; 537];
b = 3;
b_fit = temp\(prop - b) % (y - b) = a*x
figure(1)
plot(temp, prop, 'pg')
hold on
plot(temp, b_fit*temp, '-r')
hold off
grid
类别
在 帮助中心 和 File Exchange 中查找有关 Get Started with Curve Fitting Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!