If you have a two-dimensional image of the intensity of the shades of gray stored in the matrix A, you can set the bottom half to black by doing the following:
centerIndex = round(size(A,1)/2); %
A(centerIndex:end,:) = cast(0,class(A)); %
%
This works by first getting the number of lines in A, using the SIZE function , dividing it by 2 and rounding to get the integer index near the center of the image height. Then the vector centerIndex:endindexes all the rows from the central index to the end, and :indexes all the columns. All of these indexed items are set to 0 to represent black.
CLASS A, 0 , function CAST. , 0, , A .
, :
mask = true(size(A)); %
centerIndex = round(size(A,1)/2); %
mask(centerIndex:end,:) = false; %# Set the lower half to false
mask true (.. "1" ) , , false (.. "0" ) , 0. mask false . , , :
A(~mask) = 0; %
%