MATLAB Answers

How to change the color of a graph only in a particular section?

135 views (last 30 days)
M G on 17 Mar 2011
Hey all,
I was just wondering if there is a way to change a particular part of a plot to another color? Suppose we have a plotted signal in BLUE and we wannan show the main response (let's say with the highest amplitude) in RED.


Sign in to comment.

Accepted Answer

Jan on 17 Mar 2011
You can draw different lines.
t = 0:0.02:4*pi;
y = sin(t);
index = (y >= 0);
plot(t, y, 'b');
plot(t(index), y(index), 'r');

  1 Comment

Matt Tearle
Matt Tearle on 22 Mar 2011
A nice trick to remove points graphically is to set them to NaN. Eg
t = 0:0.02:4*pi;
y = sin(t);
z1 = y;
z1(y>=0) = NaN;
z2 = y;
z2(y<0) = NaN;
And while I'm here, I might as well peddle my wares:

Sign in to comment.

More Answers (0)