Using Fill function to shade between two data plots
5 views (last 30 days)
Show older comments
I have a data set which I like to highlight the upper bound and lower bound of the curve. I tried with the following code and does it seem to work. In addition, I would like to change the x axis to a 5 minute time interval. Hope someone can help me. Thank you.

The code which I used
y = data(:,1);
y1 = y + 0.2 ;
y2 = y - 0.2;
time(:,1) = 0:3744;
plot(time,y1,':k', 'LineWidth',2)
hold on
plot(time,y2,':k', 'LineWidth',2)
grid on
fill_between_lines = fill( [time fliplr(time)], [y1 fliplr(y2)], 'b' );
0 Comments
Answers (1)
Star Strider
on 23 Jul 2017
If you want to fill the area between the plots, something like this (using the patch function) will work:
t = linspace(0, 12*pi, 250); % Create Data
s1 = sin(t)+2; % Create Data
s2 = sin(t + pi/6); % Create Data
figure(1)
patch([t fliplr(t)], [s1 fliplr(s2)], 'b')
grid
Without your data, this is as close as I can get.
Plotting your x-axis in 5-minute intervals could be as easy as simply re-scaling it by multiplying the x-axis vector by a constant (depending on what the current units are) to create the appropriate 'TickLabel' values.
2 Comments
Star Strider
on 23 Jul 2017
My pleasure.
The data you posted in your plot image do not look anything at all like the data in the file you attached.
D = load('Wendy Lim data_field.txt');
t = 0:length(D)-1;
figure(1)
plot(t, D(:,1), t, D(:,2))
grid

What do you want to do?
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!