Update multiple plot fills using XData and YData

13 ビュー (過去 30 日間)
Jeremy
Jeremy 2018 年 1 月 29 日
コメント済み: Walter Roberson 2018 年 1 月 30 日
I was doing the following to generate n filled areas on a graph between n pairs of upper and lower curves.
for i = 1:n
x = % x values, function of i
y1 = % upper curve, function of i
y2 = % lower curve, function i
fill([x fliplr(x)], [y2 fliplr(y1)]);
hold on
end
However, I need to be able to plot an empty fill, and then add the fills in a loop using XData and YData, like this (I know the following won't work, but schematically)
h = fill(nan, nan, 'r');
for i = 1:n
x = % x values, function of i
y1 = % upper curve, function of i
y2 = % lower curve, function i
h(i).XData = [x fliplr(x)]
h(i).YData = [y2 fliplr(y1)]
end
What's the proper way to do this? My need for this stems from using scrollplots, which doesn't work well with re-plotting the data, but instead you need to update the data of the existing plot if changes are made. Any ideas?
  1 件のコメント
Jan
Jan 2018 年 1 月 29 日
It is not clear, what you want to do. What is "an empty fill"? "Doesn't work well" is no clear description of the problem you have.

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

回答 (1 件)

Jan
Jan 2018 年 1 月 29 日
編集済み: Jan 2018 年 1 月 29 日
[EDITED] Sorry, I've posted some nonsense code here by accident. Thanks, Walter. I do not remove the answer to keep the valuable comments.
  8 件のコメント
Jeremy
Jeremy 2018 年 1 月 30 日
I also tried (with just 3 entries)
(this works)
p3 = [fill(nan, nan, 'r') fill(nan, nan, 'r') fill(nan, nan, 'r')
and
(this doesn't)
p3(1, 1:3) = fill(nan, nan, 'r')
Replacing the x & y data of both attempts in a loop with
p3(1, i).XData = [x fliplr(x)];
p3(1, i).YData = [y2 fliplr(y1)];
Any reason why those two behave differently?
Walter Roberson
Walter Roberson 2018 年 1 月 30 日
p3(1, 1:3) = fill(nan, nan, 'r') would assign the same patch handle to those elements.
The easiest fix is to loop. But you could use an implicit loop such as
arrayfun(@(~) fill(nan,nan), 1:3)

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

カテゴリ

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

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by