Real-Time Workshop use Embedded Matlab Function to generate random numbers
2 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
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.
0 Comments
More Answers (1)
See Also
Categories
Find more on Simulink Coder in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!