Implement Curve Fitting Code in Simulink block

Hello,
I am trying to implement some code, which was generated in the Curve Fitting Tool, into my Simulink model with a Matlab function block. The script fits a surface on three inputs. With the other two inputs I want to evaluate a point on the calculated surface. I already added some code to make this script work, but something is still missing. I think, that it has something to do with a proper declaration of the fitresult variable. The code below gives the error message "MATLAB expression 'fit' is not numeric.".
function force_n = fcn(travel, pressure, force, travel_n, pressure_n)
% Create a fit.
%
% Data for 'airspring' fit:
% X Input : travel
% Y Input : pressure
% Z Output: force
% Output:
% fitresult : a fit object representing the fit.
% gof : structure with goodness-of fit info.
%
% See also FIT, CFIT, SFIT.
%%own code
coder.extrinsic('prepareSurfaceData');
coder.extrinsic('fit');
fitresult = coder.nullcopy(zeros(size(1)));
force_n = 0
Auto-generated by MATLAB on 20-Nov-2016 20:35:21
% Fit: 'airspring'.
[xData, yData, zData] = prepareSurfaceData( travel, pressure, force );
% Set up fittype and options.
ft = 'linearinterp';
% Fit model to data.
fitresult = fit( [xData, yData], zData, ft, 'Normalize', 'on' );
%%output data
force_n = feval(fitresult,travel_n,pressure_n)
%force_n = fitresult(travel_n,pressure_n)
If someone wants to test the code I've attached a model with the code block and the input data. It would be great, if anyone has a solution or an idea how to solve this problem!
Thomas

댓글 수: 1

Even I am facing the same problem. Getting same error 'fit is not numeric'. Do let me know if you have found the solution. It would be helpful.

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

답변 (0개)

카테고리

도움말 센터File Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기

제품

질문:

2016년 11월 22일

댓글:

2017년 7월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by