How to use generated code from cftool to find unknown variables
1 回表示 (過去 30 日間)
古いコメントを表示
I have three variables x y and z where x is speed (mx1 array), y is torque (nx1 array), z is efficiency (mxn array). This is a motor data. On using auto fit in cftool it chose interpolant-linear.
I want to find efficiency (z)of the motor at any given speed and torque (i.e x and y). I don't know what to do after generating the code and saving the results in workspace.
4 件のコメント
Walter Roberson
2021 年 4 月 5 日
z_at_query = interp2(x, y, z.', x_query, y_query)
The .' on z is important. Your data has x going down columns, but in MATLAB x goes across rows.
回答 (2 件)
Steven Lord
2021 年 4 月 1 日
The fitted object you export to the workspace is an sfit object. You can evaluate an sfit object by passing the values at which you want to evaluate it into the object as shown in the example on that documentation page. The same holds for cfit objects:
load census
f = fit(cdate, pop, 'poly2')
plot(cdate, pop, 'o-') % show the data
hold on
plot(1985, f(1985), 'x') % show the fitted value for 1985
The X looks to be pretty close to the line.
Walter Roberson
2021 年 4 月 5 日
The use of interpolant in this case can be replaced by just calling interp2() without using cftool at all.
x y and z where x is speed (mx1 array), y is torque (nx1 array), z is efficiency (mxn array).
z_at_query = interp2(x, y, z.', x_query, y_query)
The .' on z is important. Your data has x going down columns, but in MATLAB x goes across rows.
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!