function N=set_numberofcomponents(yy,op,dir)

if(nargin~=3)
    narginerror();
end

stindex=set_startindex(yy,dir);

if(strcmp(dir,'horizontal')==1)
    N=op.xdim-stindex+1;
elseif(strcmp(dir,'vertical')==1)
    N=op.ydim-stindex+1;
else
   error('Specify the direction.');
end