This enhancement has been incorporated in Release 2009b (R2009b). For previous product releases, read below for any possible workarounds:
You can work around this error by setting the size of the Stateflow variable dynamically at runtime. In the Model Explorer, add a script into the InitFcn callback function to set the size of the Stateflow variable "a" every time the model is run.
For this script, you need to obtain handles to Stateflow objects. See the documentation "Using the Stateflow API" available at the following URL:
In particular, the "Quick Start for Stateflow API" through "Accessing Existing Stateflow Objects" sections provide information about accessing object handles.
The following sample code shows how to set the size of Stateflow data
variable "a" to equal the size of MATLAB workspace variable "x", using
commands in the InitFcn callback function:
rt = sfroot;
m = rt.find('-isa','Simulink.BlockDiagram');
onState = m.find('-isa','Stateflow.Data','-and','Name','a');
onState.Props.Array.Size = num2str(length(x));
A sample Stateflow model is attached as an example. To run the model, create a MATLAB workspace variable "x", as in this example:
N can be any number. The Stateflow model outputs the sine of "x" into a MATLAB workspace variable "v". By accessing the handles to objects in the Stateflow chart, you can automatically set the size the Stateflow data parameter "a" to equal the size of the MATLAB workspace variable "x".
Best Answer