0
votes

Is there any way to do i.e.

Surface = scatteredInterpolant(measurement_xz(:,1)*1E-3,measurement_xz(:,2)*1E-3,measurement_xz(:,3));

where measurement_xz is some data in a startup script for my simulink model and then use Surface in an embedded matlab function in the simulink model, i.e.

///embedded matlab function

function V = fcn(x,z)
V = Surface(x,z);

? When I i.e. try to use Surface as a parameter for V like

function V = fcn(x,z,Surface)
V = Surface(x,z);

with Surface set as parameter in the Ports and data manager I get the error

Expression 'Surface' for initial value of data 'Surface' must evaluate to a numeric or logical.

1
What is a embedded matlab function, I never heard of it. I assume you are talking about one of these: A callback function, an "interpreted MATLAB function" block or a "MATLAB function" block?Daniel
I meant the matlab function blockVGD

1 Answers

1
votes

What you are trying to do is not supported by the Matlab Function block, MATLAB is unable to generate code for it. The problems are:

  • You are trying to access the variable Surface which is not visible in the scope
  • scatteredInterpolant is not supported at all for code generation (at least in my MATLAB version, might be improved in recent Versions).

To fix this on a code level, you could switch to interpreted MATLAB code. This can be done either switching to a Interpreded MATLAB block or using coder.extrinsic. It is a quick and simple fix, but I recommend not to do this because it will probably result in a slow model. Instead I recommend to switch to a lookup table, which is also capable of interpolating.