Using Fill function to shade between two data plots

5 visualizaciones (últimos 30 días)
Wendy Lim
Wendy Lim el 23 de Jul. de 2017
Comentada: Star Strider el 23 de Jul. de 2017
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' );

Respuestas (1)

Star Strider
Star Strider el 23 de Jul. de 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 comentarios
Wendy Lim
Wendy Lim el 23 de Jul. de 2017
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 el 23 de Jul. de 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?

Iniciar sesión para comentar.

Categorías

Más información sobre Annotations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by