How to use generated code from cftool to find unknown variables

조회 수: 4 (최근 30일)
DARSHAN N KANNUR
DARSHAN N KANNUR 2021년 4월 1일
답변: Walter Roberson 2021년 4월 5일
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
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.
DARSHAN N KANNUR
DARSHAN N KANNUR 2021년 4월 5일
Thank you so much. it worked. How to accept your answer.

댓글을 달려면 로그인하십시오.

답변 (2개)

Steven Lord
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')
f =
Linear model Poly2: f(x) = p1*x^2 + p2*x + p3 Coefficients (with 95% confidence bounds): p1 = 0.006541 (0.006124, 0.006958) p2 = -23.51 (-25.09, -21.93) p3 = 2.113e+04 (1.964e+04, 2.262e+04)
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.
  댓글 수: 1
DARSHAN N KANNUR
DARSHAN N KANNUR 2021년 4월 5일
could you please edit the code and send as per my requirement. where x, y, z variables are plotted using cftool with interpolant linear. where i should find z value for any x and y input.

댓글을 달려면 로그인하십시오.


Walter Roberson
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.

카테고리

Help CenterFile Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by