Thanks. I solved this in a following way!
    %Defining a colormap
  CMap=colormap(jet(nsamples));
  %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.)
  init_Y_p_sorted=sort(Y_p(1,:));
%Plotting curve by curve in a loop
for j=1:nsamples
ph=plot(X_p(:,j), Y_p(:,j));  
%Find the sorted index of a initial coordinate
CMap_ind=find(init_Y_p_sorted==Y_p(1,j));  
set(ph,'Color',CMap(CMap_ind,:));
hold on;
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.
