Thanks. I solved this in a following way!
%Defining a colormap
%Sorting the initial y-coordinates for colormap (So colors depend on the initial y coordinate of a particular curve. Could be some other variable too.)
%Plotting curve by curve in a loop
%Find the sorted index of a initial coordinate
Only problem is that if nsamples is a large number, then the colorbar of the figure becomes totally black so somekind of bining should be still added.