Discussion:
Simulink - Embedded Matlab Function - Size of function not bounded error
(too old to reply)
Elliot
2011-07-18 18:22:15 UTC
Permalink
Hey all,
I'm trying to convert a .m file into something usable by a user defined function block in simulink but am having trouble with the following style of equation:

x = exp([-y:y]);
where y is an integer which normally has a value between 40 and 120.

Running this through simulink results in the following error:
------------------------------------------------
Computed maximum size of the output of function 'colon' is not bounded.
Static memory allocation requires all sizes to be bounded.
The computed size is [1 x :?].

Function 'testing.m' line 8, column 14:
"[-y:y]"
----------------------------------------------------

I know simulink doesn't like variably sized arrays/matrices but I'm not sure I can set an upper bound in this case since it's referring to the operation itself rather than x or y.
Anyone know of a potential work around for this?

Cheers.
Phil Goddard
2011-07-18 19:13:08 UTC
Permalink
What sort of user defined function: Embedded MATLAB, S-Fuction, MATLAB Fcn Block?

Is y and input?
Is x an output?
Or are they local variables?

Phil.
Elliot
2011-07-18 21:39:09 UTC
Permalink
Post by Phil Goddard
What sort of user defined function: Embedded MATLAB, S-Fuction, MATLAB Fcn Block?
Is y and input?
Is x an output?
Or are they local variables?
Phil.
Sorry should have been more clear. It is an Embedded Matlab Function block, x and y are just local variables in this case, though there is a similar function towards the end of the code where the "x" is an output (haven't quite made it that far though).

Thanks,
-Elliot
Phil Goddard
2011-07-18 21:46:09 UTC
Permalink
You need to use something like an "assert" function prior to the colon operator so that the EML block knows an upper bound on your y variable.

A example, where y is the output in this case, would be

%%%%%%%%%%% Cut here %%%%%%%%%%
function y = fcn(u)
%#eml
assert(u<100);
vTemp = -u:u;
y = exp(vTemp)';
%%%%%%%%%%% Cut here %%%%%%%%%%

Search the doc for the text "Specifying Upper Bounds for Local Variable-Size Data" to see where this is documented.

Phil.
Elliot
2011-07-19 09:42:12 UTC
Permalink
Post by Phil Goddard
You need to use something like an "assert" function prior to the colon operator so that the EML block knows an upper bound on your y variable.
A example, where y is the output in this case, would be
%%%%%%%%%%% Cut here %%%%%%%%%%
function y = fcn(u)
%#eml
assert(u<100);
vTemp = -u:u;
y = exp(vTemp)';
%%%%%%%%%%% Cut here %%%%%%%%%%
Search the doc for the text "Specifying Upper Bounds for Local Variable-Size Data" to see where this is documented.
Phil.
Works just fine now, cheers!

-Elliot

Loading...