Using Fill function to shade between two data plots

12 次查看(过去 30 天)
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' );

回答(1 个)

Star Strider
Star Strider 2017-7-23
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 个评论
Wendy Lim
Wendy Lim 2017-7-23
I have tried with your recommendation but it doesn't seem to work. I have attached my data. What's the reason for not working the first round? Thank you!
Star Strider
Star Strider 2017-7-23
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?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by