MATLAB: How to build a model containing a Stateflow chart using MATLAB functions in a transition with Real-Time Workshop Version 7.3 (R2009a)

buildmlexpressionsimulink coderstateflowtransition

I want to build a simple model including a stateflow chart which is using a MATLAB function (mlExpression) in one of its transitions.
 
{data=ml.rand(1);}
When building the model I receive an error Real-Time Workshop error message:
  ERROR: RTW incompatible MATLAB function 'rand' in transition {data=ml.rand(1);}
How can solve this error?

Best Answer

It is not possible to build Stateflow charts containing mlExpressions even if the used MATLAB functions are part of the Embedded MATLAB function library.
As a workaround you can create an Embedded MATLAB function in your stateflow chart which is implementing the mlExpression that was previously used in the transition.
Now you can call the Embedded MATLAB function in the transition and build the model with Real-Time Workshop. Make sure that you are using only functions from the Embedded MATLAB function reference subset inside the Embedded MATLAB function. The subset of supported functions can be found at:
>> web([docroot,'/toolbox/eml/ug/bq1h2z7-9.html'])