Simulink - Embedded Matlab Function - Size of function not bounded error

1 view (last 30 days)
When compiling the following embedded matlab function, i get this 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 :?].
at this line: "x(end):epsi(1)/5:x(1)"
The embedded matlab function (partially):
function [z, stat] = simps5(x,y)
%-- Make sure x and y are column vectors, or y is a matrix. z=0; stat=0;
if sum(isnan(x)) > 0 sum(isnan(y)) > 0
disp('x or y has zero size!!!');
return;
end
xorig = x; yorig = y; stat = 1;
if isempty(xorig) == 1 isempty(yorig) == 1
disp('x or y is empty!!!');
z = 0;
stat = 2;
return;
end
stat = 0; epsi = mean(abs(diff(x))); epsiy = mean(abs(diff(y))); if epsiy(1) == 0
z = y(1)*abs(x(end)-x(1));
return;
end
if epsi(1) == 0
z =0;
return;
end
stat2 = 0;
coder.varsize('new_res',1000000); if x(1) > x(end)
assert(x(1)<2);
assert(x(end)>-2);
assert(epsi(1)>1e-2);
assert(epsi(1)<1e2);
new_res = x(end):epsi(1)/5:x(1);
new_res = sort(new_res,'descend');
else
new_res = x(1):epsi(1)/5:x(end);
end
  2 Comments
Ketan
Ketan on 13 Dec 2013
Hi Benoit,
I tried the following code:
function y = fcn(x,step)
if(x(1) > x(end))
assert(x(1)<2);
assert(x(end)>-2);
assert(epsi(1)>1e-2);
assert(epsi(1)<1e2);
new_res = x(end):epsi(1)/5:x(1);
else
new_res = x(1):epsi(1)/5:x(end);
end
y = numel(new_res);
end
Where x is [10,1] input and step is a scalar input. It errored for the colon expression in the else condition. That makes sense to me because asserts are required within the else block similar to the first if-block. After adding asserts to the else block things work.
I am not sure why you are seeing this error for the colon expression in the first if block. Any chance you can provide a full-set of code that reproduces this error?
Ketan
Benoit
Benoit on 16 Dec 2013
Hi Ketan,
Thank you for your answer. It is good to know that it works in that way. One thing to add in the code is that:
epsi = mean(abs(diff(x)))
as I wrote in my last message. Sorry, it was not clear with the code "styles". I think i wrote everything that was necessary to understand the code of the function. The rest is just using this new_res as new resolution for x, so it does not affect the error I keep receiving.

Sign in to comment.

Answers (1)

Benoit
Benoit on 13 Dec 2013
nobody?

Products

Community Treasure Hunt

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

Start Hunting!