MATLAB: Changing color of point in stem plot based on value

colorgraphplotplottingstemvalue

I'm doing a stem plot of one vector in MATLAB. Can I change the color/marking of only the values that are zero in that vector? Right now, the 'points' of zero are only empty spaces in the stem plot.

Best Answer

No, but that doesn't mean you can't get what you want.
t = (-3*pi:.1:3*pi);
y = round(sin(t)*5)/5;
idx = y~=0;
ynz = y(idx);
yz = y(~idx);
h = stem(t(idx),ynz,'fill','--');
hold on
h(2) = stem(t(~idx),yz);
set(get(h(1),'BaseLine'),'LineStyle',':')
set(h(1),'MarkerFaceColor','red')
set(h(2),'MarkerFaceColor','k','Markersize',8)