Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to fix the Error: "Computed maximum size is not bounded. Static memory allocation requires all sizes to be bounded."

737 views
Skip to first unread message

aidin

unread,
Aug 29, 2014, 5:05:08 AM8/29/14
to
Hello everyone,
I'm working on a simulink project, I used the "Tracking Cars Using Optical Flow" simulink project in matlab (which is available in matlab's help) and I changed it somehow to meet my needs.

In a user defined function I have 2 inputs and my func is ImCropper(u,Image).
u is a -variable size- vector which indicates the starting point and width and height of some rectangles, you can show it in matlab standard [x, y ,width , height] for each rectangle as one row.

The function should crop the Image in the parts which is mentioned in u. I mean crop those rectangles of u in Image.

Because u has a variable size, whenever I use a temporary variable to get the cropped parts the error occurs, I mean I can't reserve dynamic memory for my temporary variable.

My answer is laid on the page "Generate Code for Variable-Size Data" part in help. My version of matlab is 2014 although the help is not for that version so the guides are not so much useful for me, please someone help me.

At last I want to post here my code :

function y = ImCropper(u,Image)
%#codegen
coder.varsize('CroppedRect');

%a row of u indicates [x , y ,width ,height] of a rectangle.
%y should be a cropped rectangle of Image where it's position is declared by u.

CroppedRect=Image(u(2):(u(2)+u(4)),u(1):(u(1)+u(3))) %Here the error occurs :(

y=CroppedRect;
end

mh

unread,
Sep 12, 2014, 2:06:48 PM9/12/14
to
On Friday, August 29, 2014 5:05:08 AM UTC-4, aidin wrote:
> CroppedRect=Image(u(2):(u(2)+u(4)),u(1):(u(1)+u(3))) %Here the error occurs

It's sometimes helpful to convert colon expressions of the form a:(a+b) to a + (0:b). That is to say, it is helpful when the compiler knows something about the range of b. The compiler infers information like that automatically, but it may sometimes take the hint if you use the assert function. For example, if b is known to be less than the number of columns in an input matrix X, then you might put in the seemingly do-nothing line of code

assert(b <= size(X,2),'A size hint turned out not to be true!');

before the cropping. Also, the compiler can track ranges on some elements of small vectors, but you are better off relying on scalars, if possible, so if you can't get it to work with a vector u, consider defining the function like so

function y = ImCropper(u1,u2,u3,u4,Image);

0 new messages