Why does Embedded MATLAB fail to detemrine the size of my expression in Simulink 7.2 (R2008b)?

12 views (last 30 days)
I use the following MATLAB code in an Embedded MATLAB Function block:
function y = fcn(u)
y = eye(6);
y(1,u-1:u+1) = 2
I receive an error message similar to:
Size of index expression is not statically known.
or
Could not determine the size of this expression

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 20 Jun 2011
This enhancement has been incorporated in Release 2011a (R2011a). For previous product releases, read below for any possible workarounds:
In this case, Embedded MATLAB does not recognize that the size of the expression is constant. To workaround this issue, define a vector of indices to be used in the assignment, as in this example:
function y = fcn(u)
y = eye(6);
T = (0:2)+u-1; % Define the vector of indices to be assigned
y(1,T) = 2; % assign values in the large matrix
  2 Comments
chef13
chef13 on 24 Jul 2015
Instead of :
ind+2*(ind-1):3*ind,ind+2*(ind-1):3*ind
I wrote
3*ind-2:3*ind, 3*ind-2:3*ind
Which is the same thing.
And it worked.

Sign in to comment.

More Answers (0)

Products


Release

R2008b

Community Treasure Hunt

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

Start Hunting!