MATLAB: Error using ones Size inputs must be integers

arrayimage processingmathematicsMATLABmatlab functionmatrix manipulation

hello every one i have a problem with my code for error
r =[zeros(size(img2,1),size(img2,2)) ones(size(img2,1),size(img2,2)/2)];
where img2 an image of size (111 235)
Error using ones
Size inputs must be integers
and i want to have an image of the same size of img2

Best Answer

If you want an image the same size as img2 then
r = zeros(size(img2), class(img2));
after which you can assign ones into an appropriate section of r
Your phrase size(img2,2)/2 has a problem when the number of columns in img2 is odd, as it does happen to be. 235/2 is not an integer.
r(round(end/2)+1:end, round(end/2)+1:end) = 1; %perhaps