Using Fill function to shade between two data plots
5 ビュー (過去 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' );
0 件のコメント
回答 (1 件)
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 件のコメント
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 Center および File Exchange で Annotations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!