How to use vectors inside the fittype function
5 次查看(过去 30 天)
显示 更早的评论
Hello,
I am using the fit function in order to take experimental data and fit it with an expression. The expression that I need to use also uses multiplication of variables which are vectors, within the expression. The problem is that the fittype is a string, which only "knows" the independent variable and the coefficients, as far as I understand. So it does not work, and I dont know how to send these vectors into the expression so fittype can use it. It is best to give a simplified example:
lets say I have only two data points (x1,y1),(x2,y2), and I have another vector, V, which has two elements in it. Mathematically, the expression I want to fit is A1*V./x ( where x is (x1,x2) ), and as a function this will give an answer which is a vector with 2 elements. But the fittype string would be 'A1*V./x' and the symbol V has no meaning since it is not the dependent variable x, and it is not a coefficient.
how can I solve this?
Thank you, Itai.
0 个评论
回答(2 个)
Elizabeth Reese
2017-12-4
You can do this by supplying an anonymous function for the expression in fittype instead of a string.
For example
g = fittype( @(a1,v,x) a1*v./x, 'problem', 'v' );
f = fit(xdata,ydata,g,'problem',V)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Linear and Nonlinear Regression 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!