Fill command issue for time series

2 ビュー (過去 30 日間)
William Garrett
William Garrett 2020 年 3 月 31 日
編集済み: Les Beckham 2020 年 4 月 5 日
I am trying to fill the space in between two lines on a time series
I have created a 45x1 cell array of datenum variables (X), a 45x1 cell array for the blue line (Y1) and a 45x1 cell array for the red line (Y2)
The plot of these two lines can be seen in the attatched image 'Lines'
I want to fill in the space in between these lines
However, when I use the following script, the space in between the lines does not fill - as seen in the image 'Fill'. What am I doing incorrectly?
EDIT: I have attached some sample data, Y1 is the higher values
>> plot(X, Y1, 'b', X, Y2, 'r')
>> hold on
>> fill([X fliplr(X)],[Y1 fliplr(Y2)],'c')

採用された回答

Les Beckham
Les Beckham 2020 年 4 月 5 日
編集済み: Les Beckham 2020 年 4 月 5 日
Based on your sample data, you need to make a simple change to your code. Since your vectors are columns, you need to concatenate using a semicolon so you get vectors and not nx2 matrices.
Here is the result after making this change:
plot(x, y1, 'b', x, y2, 'r')
hold on
fill([x; flip(x)], [y1; flip(y2)], 'c', 'edgecolor', 'none')

その他の回答 (1 件)

Prabhanjan Mentla
Prabhanjan Mentla 2020 年 4 月 3 日
In general fill function is used to fill the polygons with specified color( c ).
x = 1:5;
y1 = sin(x) + 2;
y2 = sin(x);
fill([x fliplr(x)], [y2 fliplr(y1)], 'c')
This code fills the area between y1 and y2.
Plot followed by hold on and fill, may also work in the same way as above code.
Here in your case I assume there is a problem with your input data.
Refer the below link.
  1 件のコメント
William Garrett
William Garrett 2020 年 4 月 5 日
編集済み: William Garrett 2020 年 4 月 5 日
Thank you for your help; however one thing confuses me.
On the attatched link the answer says to sort your data as if walking around the x.y co-ordinates. Are you able to expand on what this means?
I have attached to the question some sample data if this helps, Y1 is the higher values
Thank you

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

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by