Real-Time Workshop use Embedded Matlab Function to generate random numbers

2 views (last 30 days)
Hi everyone, In the Real Time Workshop I am trying to use in an embedded Matlab function in Stateflow the two function “rand” and “round”, but I always get the following error: Failed to eliminate a use of the MATLAB function 'rand/round'. For non-simulation builds, uses of unsupported MATLAB functions are eliminated if they do not effect the model outputs. The code that I am using is the seguent:
function calculation_one
eml.extrinsic('rand',’round’);
random_number=rand(1,9);
Status_vector_cells= round(0+(99-0).*random_number);
I would like please to know:
-If the two function are in the list of supported Matlab functions for RTW code generation;
-if it is possible to know where can I find the list of supported Matlab functions for RTW, as I have looked long without find it;
-If these two functions are not supported, is there any other way to generate random number through m file? I have tried with the Simulink block “Random Source” or “Random Number”, and the generation code does not give any error, but I would prefer to use some Matlab code that is then implementable inside Stateflow through the embedded Matlab function;
Can somebody help me?
I am using Matlab 2009b 32bit with a multi core PC.
Really Thanks In advance
Andrea

Accepted Answer

Kaustubha Govind
Kaustubha Govind on 15 Aug 2013
Here is the current list of MATLAB functions supported for code-generation, and I see that both RAND and ROUND are on the list. However, it is likely that you are using an older version of MATLAB/Simulink where these functions were not on the list (you will need to look in the documentation that came with your installation to see the list for your version). Another way of verifying this is to remove the declaration eml.extrinsic('rand',’round’) and see if you receive an error about the functions not being allowed. If you do see such an error, the only workarounds might be to either use the corresponding Simulink blocks or upgrade to a newer version.

More Answers (1)

Andrea
Andrea on 15 Aug 2013
Really thanks for the speed of answer!!! I have already tried to remove the declaration eml.extrinsic('rand',’round’), the generation code does not give any error, but only the round function works properly, the rand function generate always the same number series. As I cannot jump to other Matlab version (becasue of compatibily problem with the Program in the Target PC for RTW) I am trying to insert the random generation through a Simulink Embedded Function in Stateflow, and it seems to work properly.
Thanks again Andrea

Categories

Find more on Simulink Coder in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!