Pergunta

Simulink has a module called "Matlab Function," which allows you to create a custom function in a Simulink flow diagram.

I implemented a simple function in a Simulink Matlab Function module. My function contains a call to Matlab's built-in rms(). When I run the Simulink model, I get the following error:

The function 'rms' not supported for standalone code generation

If I remove rms from my Matlab Function in the Simulink model, the error goes away and the model runs flawlessly.

Questions:

  • Is there a way to use Matlab's rms in Simulink?
  • Are there many other native Matlab calls that can't be used inside Simulink?
Foi útil?

Solução

I just wanted to clarify and expand upon some points made in learnvst's answer.

Even if you are simply trying to simulate a model containing a MATLAB Function block and are not explicitly attempting to perform code generation, you will still get the not supported for standalone code generation error.

As learnvst indicated, there are multiple restrictions on functions that can be used with code generation. However, if you just want to simulate your model, Simulink allows you to do this if you signify these "black-listed" functions as being extrinsic. This lets Simulink know that the functions will be used for simulation purposes only and won't be part of code generation.

In your particular case, add the following line of code somewhere before your call to rms:

coder.extrinsic('rms');

Declaring a function as extrinsic in a MATLAB Function is often useful even when you are performing code generation. For example, you may want to visualize your data using the plot command during simulation, but obviously would not need the plot command to be part of generated code.

Refer to this doc for more info on declaring functions to be extrinsic.

Outras dicas

The not supported for standalone code generation part of the error suggests to me that you are trying to use a product like Matlab Coder to make an executable or native code. If this is the case, there are many naive calls that cannot be used directly in both core Matlab and the toolboxes. The coder products only support a subset of the language. More information can be found here . . .

http://www.mathworks.co.uk/products/matlab-coder/description2.html

As for your call to rms, it is only calculating the root of the mean of the squares. Try creating an alternative using something like . . .

sqrt(mean(x.^2))

...where x is the signal.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top