Clear Filters
Clear Filters

Colour Segments of graph

2 views (last 30 days)
Michael Constantine
Michael Constantine on 10 Sep 2020
Answered: Monisha Nalluru on 14 Sep 2020
I have plotted a voltage vs time graph and wish to colour sections of it, and want to know the best way to do this? I will attach a screenshot of the graph I have plotted and an example of how I wish to colour it.
Cheers

Answers (1)

Monisha Nalluru
Monisha Nalluru on 14 Sep 2020
fill, patch functions are used to fill the area under a plot
As an example, you can refer to the following code
x1=0:pi/20:pi;
y1=sin(x1);
patch(x1,y1,'r')
x2=pi:pi/20:2*pi;
y2=sin(x2);
patch(x2,y2,'b')
x3=2*pi:pi/20:3*pi;
y3=sin(x3);
patch(x3,y3,'y');
hold on
x=pi/60:pi/20:pi;
y=sin(x);
fill(x,y,'k') // color some red area by black
hold off

Community Treasure Hunt

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

Start Hunting!