Implement Curve Fitting Code in Simulink block
Show older comments
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 Comment
Rohan Gupta
on 6 Jul 2017
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.
Answers (0)
Categories
Find more on Linear and Nonlinear Regression in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!