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

M
Mariahernandez · Aug 27, 2020 · 1.9K views
Question
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.
Expert Answer
Profile picture of Prashant Kumar
Prashant Kumar PhD Expert
Answered Nov 20, 2025

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');
Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!