M level 2 S-Function TLC file

4 views (last 30 days)
João
João on 3 Jan 2023
Answered: Manoj Mirge on 17 Apr 2023
Hi everyone, I created a M-S function that can handle N dimension in order to interpolate acording to specific data. Everyhting seems good until
I tried to generate code here were my problems:
  1. code generator was not able to use "interpn" (i used a maltab fuction in a m file and call it the block function output)
  2. tried to put everything in a matlab block function , same problem as before.
Here a share main my function, i collect data from a json file and fill my arguments with inside simulink values :
function [Vq_N_D]=interpolationND(jsonfilename,varargin)
end
Here my block Sfunction, for a 3D interpolation (the last part) :
...
function Output(block)
Xq= block.InputPort(1).Data;
Yq = block.InputPort(2).Data;
Zq = block.InputPort(3).Data;
Vq=interpolationND(block.DialogPrm(1).Data,Xq,Yq,Zq);
block.OutputPort(1).Data= Vq;
%endfunction
...
Can anyone help or maybe lead me to a good direction?

Answers (1)

Manoj Mirge
Manoj Mirge on 17 Apr 2023
Hi,
I am assuming that you are using interpn function with ‘makima’ interpolation method in your S Function. The MATLAB Function block and S Function only supports the subset of MATLAB language features that are compatible with C/C++ code generation. The interpn function does not support the 'makima' interpolation method for code generation, so you cannot use it in a MATLAB Function block for code generation.
To resolve your issue, you can try using the makima function, declared as an extrinsic using the coder.extrinsic command. Your MATLAB Function block's code might look something like this:
function y = fcn(u)
coder.extrinsic('makima');
y = 0;
y = makima(1:10, 1:10, u);
end
You can read more about how to generate code for functions that are not supported for code generation in the link below:
Hope this helps.

Categories

Find more on Simulink Coder in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!