Why am I unable to initialize the local vector or matrix data in my Stateflow chart?

I created a local data array in my Stateflow chart with name 'LocalArray'. In the data dialog box, I specified its size to be 10 under the 'General' tab and I specified its initial value to be '[1:10]' in the 'Value Attributes' tab. When I try to run the model, I receive the following error message:
Expression '[1:10]' for initial value of data 'LocalArray' must evaluate to a scalar.

 Accepted Answer

This enhancement has been incorporated in Release 2008b (R2008b). For previous product releases, read below for any possible workarounds:
There are two workarounds:
1. If the initial value for each element of the vector or matrix is identical, specify this scalar value in the 'Initial Value' field. All elements of the vector or matrix will be initialized to this scalar value.
2. If the initial values for the elements of the vector or matrix are different, define a new data element with type 'Parameter' in the Stateflow chart. This data element should be the same size as the original vector or matrix. Initialize the parameter data to the desired values. For example, if your parameter is called 'foo', initialize the variable by issuing the following command at the MATLAB prompt:
foo = [1:10] ;
Then, in the default transition of the Stateflow chart, assign the parameter value to the original vector or matrix, as in this example:
LocalArray = foo;
This statement initializes the variable 'LocalArray' to the value '[1:10]'.

More Answers (0)

Categories

Products

Release

R2006b

Community Treasure Hunt

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

Start Hunting!