Changing color of point in stem plot based on value

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.

 Respuesta aceptada

Matt Fig
Matt Fig el 7 de Abr. de 2011
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)

3 comentarios

M Brown
M Brown el 7 de Abr. de 2011
Okay great- that's what I want it to look like but how would I do it if the data I plot is just a l by x matrix of numerical values
Matt Fig
Matt Fig el 7 de Abr. de 2011
In the case of a matrix instead of a vector (didn't you say in your OP that you had a vector??), each column is plotted separately. So do:
t = (-3*pi:.1:3*pi).';
y(:,1) = round(sin(t)*5)/5; % A matrix used for the call to STEM.
y(:,2) = round(cos(t)*5)/5;
idx = y~=0;
ynz = y;
ynz(~idx) = nan;
y(idx) = nan;
h{1} = stem(ynz,'fill','--');
hold on
h{2} = stem(y);
set(get(h{1}(1),'BaseLine'),'LineStyle',':')
set(h{1}(1),'MarkerFaceColor','red')
set(h{2}(1),'MarkerFaceColor','c','Markersize',10)
M Brown
M Brown el 7 de Abr. de 2011
Thank you!!!!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Line Plots en Centro de ayuda y File Exchange.

Preguntada:

el 6 de Abr. de 2011

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by