rgbImage = grayImage / max(max(grayImage));
or
rgbImage = grayImage / 255;
Which of the above is right,and reason
By definition, an RGB image has 3 channels, which implies you need a three-dimensional matrix to represent the image. So, the right answer is:
rgbImage = repmat(255*grayImage/max(grayImage(:)),[1 1 3]);
Be careful when normalizing grayImage. If grayImage is uint8 then you will lose some precision in the 255*grayImage/max(grayImage(:)) operation.
Also, normalizing grayImage depends on the data. In your question, you used two methods:
rgbImage = grayImage / max(max(grayImage));
which normalizes the grayscale image such that the maximum value in the image is 1 and
rgbImage = grayImage / 255;
which only makes sense if the values in grayImage lie in the 0-255 range.
So it really depends on what you want to do. But, if you want an RGB image you need to convert your single-channel matrix to a 3-channel matrix.