MATLAB: How show weights with different color

3d plotscolorMATLABplot

Hi,
I would like to plot lines with different weights and visualize weights with color. For example,
x = 1:100;
y = rand(50,100);
weight = rand(100,1);
plot(y,x)
x is x-axis coordinate, y is y-axis coordinate and weight is the weights for these 100 lines. I wish to plot these lines with the color proportional to the weight. Could anybody give me an idea on this? Thanks in advance.

Best Answer

See comments
h = plot(y,x); % There should be 1 handle per line object
% choose the colormap (eg, jet) and number of levels (eg, 100)
nLevels = 100;
cmat = jet(nLevels);
% Assign each weight to a row of color.
weightNorm = (weight-min(weight))./range(weight); %normalized 0:1
[~,~,crow] = histcounts(weightNorm,linspace(0,1,nLevels));
% assign color
set(h,{'Color'},mat2cell(cmat(crow,:),ones(size(h)),3))