【问题标题】:Filling area between curves introduces lines back to beginning of curves曲线之间的填充区域将线引入曲线的开头
【发布时间】:2019-04-19 18:35:03
【问题描述】:

我正在尝试为预先平滑的一些噪声曲线添加置信区间。我使用了this answer 中提出的方法。就我而言,我是这样实现的:

tcd           % Cell array contains all the original data for multiple files
tcd_smooth    % Cell array contains the smoothed data for multiple files 

% Store all time-value pairs smaller than the original data in 
% lower_bound_times, lower_bound_values and all values larger than
% the original data in upper_bound_times, upper_bound_values
lower_bound_times = time{i_file}(tcd{i_file} < tcd_smooth{i_file});
upper_bound_times = time{i_file}(tcd{i_file} > tcd_smooth{i_file});
lower_bound_values = tcd{i_file}(tcd{i_file} < tcd_smooth{i_file});
upper_bound_values = tcd{i_file}(tcd{i_file} > tcd_smooth{i_file});

% Flip order of arrays to construct closed area that can be filled
X=[upper_bound_times; fliplr(lower_bound_times)];              
Y=[upper_bound_values; fliplr(lower_bound_values)];

fill(X, Y , 1,...
    'facecolor',colorOrder(mod(i_file-1,7)+1,:), ...
    'edgecolor',colorOrder(mod(i_file-1,7)+1,:), ...
    'facealpha', 0.2, ...
    'edgealpha', 0.2);

对索引i_files 指示的多个文件执行此sn-p。置信水平被很好地填充,如下面的单线放大图所示:

但是由于某种原因,所有行的结尾都与开头相连,如下两幅图所示:

情节的右端是这样的:

我不知道如何摆脱这些返回的填充区域。

【问题讨论】:

  • 看起来您在每行上的第一个数据点再次作为最后一个条目重复。当您的最后一个数据点再次连接到第一个数据点时,这通常会出错。
  • 您确定fliplr 会沿正确的维度翻转您的数组吗?我想目标是让 x 值从最小值变为最大值,然后再回到最小值。
  • X=[upper_bound_times; fliplr(lower_bound_times)]; 中使用水平翻转fliplr 和垂直连接; 似乎是错误的。您使用行向量还是列向量?
  • 嗨@Brice 和@Andras Deak! lower_bound_timeslower_bound_values 是 4131x1 数组,upper_bound_timesupper_bound_values 是 4111x1 数组。我将尝试转置,然后立即使用, 而不是;
  • 是的,这解决了问题!如果你愿意,你可以写一个简短的答案,我可以接受。

标签: matlab plot


【解决方案1】:

X=[upper_bound_times; fliplr(lower_bound_times)]; 中使用水平翻转fliplr 和垂直连接; 似乎是错误的

如果 upper_bound_times 是列向量,则应使用上下翻转代替左右翻转:

X=[upper_bound_times; flipud(lower_bound_times)]; %flip along first dimension

如果是行向量,则应使用水平串联与,

X=[upper_bound_times, fliplr(lower_bound_times)]; %horzcat

【讨论】: