1

I would like to plot a line, and in grey-shaded X% deviation of a signal, in MATLAB. Then, I'd plot another signal and see (visually) how much of the second signal is outside the gret-shaded area.

The task I'd like to get help done is the shaded area: similar to the image attached below.

enter image description here

I am aware of similar solutions with errorbar, but I think this is a much clearer plot to visualize.

If for example I had:

x = 0:0.1:10;
y = 1 + sin(x);

What would the 5% grey-shaded plot of y look like? (that area?)

titus.andronicus
  • 517
  • 1
  • 7
  • 19

1 Answers1

5

See this answer for an example: MATLAB fill area between lines

Do you have the error of y at each sample in x? Let's assume you have and the upper bound is in variable yu and the lower bound in variable yl. Then you could plot it using:

x = 0:0.1:10;
y = 1 + sin(x);
% I create some yu and yl here, for the example
yu = y+.1;
yl = y-.1;
fill([x fliplr(x)], [yu fliplr(yl)], [.9 .9 .9], 'linestyle', 'none')
hold all
plot(x,y)

fill(X,Y,ColorSpec,...) plots a polygon with edges specified in the first two parameters. You have to fliplr (flip left-right) the arrays, so that it correctly draws the shape of the area to be filled 'in a circle' around it. The [.9 .9 .9] is the colour specification, in this case a light grey. I removed the edge by setting no line, to make it even more similar to your desired plot. One detail: plot the filled area before plotting y, because the last plotted object goes on top of the others.

Community
  • 1
  • 1
Erik
  • 4,305
  • 3
  • 36
  • 54