Two colors, one vector

5 visualizzazioni (ultimi 30 giorni)
Kathryn McCormick
Kathryn McCormick il 16 Lug 2013
I would like to plot a periodic vector, such as
x = -4*pi:0.1:4*pi;
plot(sin(x));
but to have the positive values plotted in one color and the negative values are plotted in another. Is there a simple, elegant way to do this?

Risposta accettata

Azzi Abdelmalek
Azzi Abdelmalek il 16 Lug 2013
Modificato: Azzi Abdelmalek il 16 Lug 2013
x = -4*pi:0.001:4*pi;
y=sin(x);
y2=y;
y2(y2>=0)=nan;
plot(x,y ,'r',x,y2,'g');

Più risposte (0)

Categorie

Scopri di più su 2-D and 3-D Plots in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by