Using Text inside a Embedded Matlab function

Hi,
I'm using the NIST data base to do some thermodynamic calculations (refrpopm function).
It works nice with matlab, but with simulink it doesn't work inside an embedded Matlab function. In fact, the problem is with the text input of the function (fluid selection)
for example, the code inside the embedded function: enthalpy=refpropm('H','T',375,'P',100,'water');
coder error :This operation does not support cell arrays. Use curly braces instead.
Function 'refpropm.m' (#44.6399.6412), line 135, column 33: "varargin(5+i)" Launch diagnostic report.
Thank's in advance

Answers (1)

As is documented here, cell arrays are not supported for Code Generation from MATLAB. The (Embedded) MATLAB Function first generates a MEX-file from the MATLAB code being invoked and then runs the generated MEX-file, so you cannot directly call code unsupported with code-generation. Since varargin is a cell-array, varargin(5+i) also returns a cell-array, whereas varargin{5+i} returns the elements contained at the position in the cell-array. You could try following that suggestion and modify the rest of your code accordingly to see if it works.
You could also try declaring 'refpropm' as a coder.extrinsic function to see if you can avoid code generation.
Failing that, you might be able to use either the Intepreted MATLAB Function block or the MATLAB S-function block to call your MATLAB code from Simulink - neither block attempts to generate code. Note that the 'Interpreted MATLAB Function' block only supports one input and one output however. The MATLAB S-function has more functionality, but there is a bit of a learning curve involved in writing S-functions.

Products

Asked:

on 6 Jul 2012

Community Treasure Hunt

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

Start Hunting!