MATLAB: How to create a gray scale image

digital imagesimage processingImage Processing Toolbox

Hi, i want to create a gray scale image in matlab so I write a matrix 5×7 lets say A=[0 0 0 0 0 0 0; 80 80 80 80 80 80 80;200 200 200 200 200 200 200; 110 110 110 110 110 110 110; 160 160 160 160 160 160 160;255 255 255 255 255 255 255] . Then i use the imshow command and I expect an image where every row has a different intensity, the first black, the last white and the others with intermediate values. Instead of that i get a picture where only the first row is black and the rest of them are white. what am i doing wrong?

Best Answer

A is a double. Cast it to uint8:
imshow(uint8(A));
or else use [] if you want to keep A as a double:
imshow(A, []);