Filling plot between two curves

I have two functions (BLOCK1ROWAVG and BLOCK5ROWAVG) that both have standard error values (curve#). The standard error lines will wrap the respective mean functions and I want to fill that area between the standard error, but everytime I try it the fill carries all the way to the x-axis. How do I fix my code? (if needed, you can use a function like y=x and y=x+5 with SEs of +/-1 to illustrate)
curve1 = BLOCK1ROWAVG + BLOCK1SE;
curve2 = BLOCK1ROWAVG - BLOCK1SE;
curve3 = BLOCK5ROWAVG + BLOCK5SE;
curve4 = BLOCK5ROWAVG - BLOCK5SE;
x=transpose(1:8000);
x2=[x,fliplr(x)];
inBetween1=[curve1,fliplr(curve2)];
inBetween2=[curve3,fliplr(curve4)];
%PLOT
hold all
BLOCK1 = plot(BLOCK1ROWAVG, 'r', 'LineWidth', 2);
BLOCK5 = plot(BLOCK5ROWAVG, 'b', 'LineWidth', 2);
plot(curve1,'k','LineWidth', 1);
plot(curve2,'k','LineWidth', 1);
plot(curve3,'k','LineWidth', 1);
plot(curve4,'k','LineWidth', 1);
a=fill(x2,inBetween1,'k');
set(a,'Facealpha',0.1)
b=fill(x2,inBetween2,'k');
set(b,'Facealpha',0.25)
hold off
grid on

4 件のコメント

Tommy
Tommy 2020 年 3 月 28 日
Make sure curve1, curve2, curve3, curve4, and x are all row vectors, not column vectors, in order for this to work. The idea with
inBetween1=[curve1,fliplr(curve2)];
is to make a 1x16000 vector, not an 8000x2 array. Furthermore,
fliplr(curve2)
will not actually flip curve2 if it is a column vector, as it only flips left to right.
James Parkinson
James Parkinson 2020 年 3 月 28 日
So instead of transposing my x, it should be done to the rest of my values?
James Parkinson
James Parkinson 2020 年 3 月 28 日
It worked. Thank you!
Tommy
Tommy 2020 年 3 月 28 日
Awesome no problem!

サインインしてコメントする。

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeSimulink Functions についてさらに検索

質問済み:

2020 年 3 月 28 日

コメント済み:

2020 年 3 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by