MATLAB: How to plot a sine function with each point having a z variable

colormapplot

I would like to plot say a sine function for which I have created two arrays, x and y, where y=sine(x). Now each point (x,y) has an associated z variable defined in a third array z. I would like to plot y with a heat map such that various points on the sine function have different colors based on the z value and the rest of the plot is not colored. An example of such a plot is attached.
I tried imagsc(x,y,z) but that did not work. Any hints would be appreciated.
Vahid

Best Answer

scatter(x,y,5,z)
hold on
plot(x,y,'k-')
latter two lines if want the line between points; otherwise forget it...
ADDENDUM Actually, the scatter solution works reasonably well...
>> N=1000;
>> x=linspace(0,2*pi,N);
>> y=sin(x);
>> z=linspace(-1,1,length(x));
>> scatter(x,y,15,z,'o','filled')
>>
results in:
You can 'spearmint w/ how few points can get away with and whether the number of scatter object handles becomes excessive for a plot as complex as that you show.