MATLAB: Colormap for multline plot

colormapplot

How do I change the colormap of a multiline plot and have it change the colors of the existing lines? I am using Matlab 2018b. Here is a simple example.
x = rand(10,1000);
t = 0:999;
plot(t, x)
colormap winter
colormap white
colormap flag
fh = gcf;
fh.Colormap = colormap('flag');
fh.Children(1).Colormap = colormap('flag');
For me, the colors of the lines do not change. The following also did not work, the lines are plotted using the "default" color scheme.
fh2 = figure;
fh2.Colormap = colormap('flag');
ax = axes(fh);
ax = axes(fh2);
ax.Colormap = colormap('flag');
plot(ax, t, x)
Invoking "colorbar" shows a colorbar using the desired colormap. Using colormap with surf(peaks) does change the color of that plot. How do I change the colormap of a 2D multiline plot?

Best Answer

"A colormap is matrix of values between 0 and 1 that define the colors for graphics objects such as surface, image, and patch objects. MATLABĀ® draws the objects by mapping data values to colors in the colormap." from https://in.mathworks.com/help/matlab/ref/colormap.html
But you are trying to apply colormap to line data instead of surface, image, patch data objects.