Using Fill function to shade between two data plots

조회 수: 5 (최근 30일)
Wendy Lim
Wendy Lim 2017년 7월 23일
댓글: Star Strider 2017년 7월 23일
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