Simulink - Embedded Matlab Function - Size of function not bounded error
1 view (last 30 days)
Show older comments
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
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
Answers (1)
See Also
Categories
Find more on String in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!