Assuming your image is an integer MxN matrix, where each pixel has a value corresponding to the class number (between 1 and C, where C = number of classes), and you have the Image Processing Toolbox, you could use the label2rgb function.
Example:
imgColor = label2rgb(img);
imshow(imgColor);
Alternatively you could create a colormap and generate the image using this:
map = colormap('lines');
imgColor = reshape(map(img, :), [size(img) 3]);
imshow(imgColor);
You could define your own colormap by just creating a matrix Cx3, each row corresponding to a normalized RGB color (between 0.0 and 1.0), for each class.
map = [1.0 0.0 0.0; % Red
0.0 1.0 0.0; % Green
... % And so on...
]