Take the 500x500 uint8 grayscale image, and use im2double() on it. This will give you floating point numbers. For uint8, the equation works out the same as dividing the uint8 by 255.
Now take those floating point values, and make them the third layer of an image, in which the first two layers are all zero.
img = imread('cameraman.tif');
H is now the HSV representation of the grayscale image. You can write Hue information into H(:,:,1) and Saturation information into H(:,:,2); For example,
H(:,:,1) = rand(size(img))/10;
H(:,:,2) = rand(size(img));