MATLAB: Does the FIGURE command create two figures when I set the colormap property in MATLAB 7.3 (R2006b)

MATLAB

I am creating a figure using the FIGURE command in MATLAB 7.3 (R2006b). When I set the 'Colormap' property of the figure to "gray" using the following statement:
h = figure('Colormap',gray);
two figures are generated instead of one.

Best Answer

This behavior is expected, and is due to the following:
If there are no input arguments to GRAY, the colormap property value 'gray' will call GCF to get the default Colormap length, and this will create the new figure.
As a workaround, specify the colormap length in the command as follows:
h = figure('Colormap',gray(256));