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);