Data 'xR' (#27) is inferred as a variable size matrix, while its specified type is something else ?

2 views (last 30 days)
Hi There
The following function must give me tow output xR and yR from an image binary image type
function [xR,yR]=findXY(img)
accumulationVertical=sum(img,2);
accumulationHorizontal=sum(img,1);
x1=find(accumulationHorizontal>0,1,'first');
x2=find(accumulationHorizontal>0,1,'last');
y1=find(accumulationVertical>0,1,'first');
y2=find(accumulationVertical>0,1,'last');
xR=floor((x1+x2)/2);
yR=floor((y1+y2)/2);
width=x2-x1;
height=y2-y1;
end
I get the following error message
Data 'xR' (#27) is inferred as a variable size matrix, while its specified
type is something else?
and Data 'xR' (#27) is inferred as a variable size matrix, while its specified type is something else?
many thankans in advance.

Answers (1)

Walter Roberson
Walter Roberson on 25 May 2015
find() with 'first' or 'last' can both return empty vectors. For example if the input image is all 0, then there is nothing to find in either vector and [] would be returned from the find(). Your outputs are therefor variable length, either [] or scalar.
Also, it is possible that Simulink does not know about the counts (1) and is assuming that find() is going to return an indefinitely long vector. If that is the case then accessing x1(1) instead of just x1, and likewise for the other variables, should do the trick. After you have corrected or the possibility of the matrix being all 0.
  3 Comments
bekhoukha mohammed
bekhoukha mohammed on 26 May 2015
yes, find is a numeric index ;
x1=find(accumulationHorizontal>0,1,'first');
accumulationHorizontal=sum(img,1); but accumulationHorizontal [];

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!