Are you trying to get someone to do your homework? Anyways you would first need to read the image using 'imread'. Use 'size' to figure out the number of rows and columns. If I represents your image, size(I,1) gives you number of rows and size(I,2) number of columns. Then based on your threshold you can set the pixel value to either 255(white) or 0(black).
Here is the sample code
I = imread('pic.jpg');
imshow(I);
for i= 1:size(I,1)
for j = 1:size(I,2)
if I(i,j) > threshold
I(i,j) = 255;
else
I(i,j) = 0;
end
end
end
figure, imshow(I)
or as an alternative you could use 'graythresh' from matlab to do the same.