代码之家  ›  专栏  ›  技术社区  ›  Axel

曲线之间的填充区域将线引回到曲线的开头

  •  0
  • Axel  · 技术社区  · 6 年前

    我正试图给一些我事先平滑过的曲线增加一个置信区间。我使用了 此答案中建议的方法。在我的例子中,我是这样实现的:

    tcd%cell array contains all the original data for multiple files
    tcd_Smooth%单元格数组包含多个文件的平滑数据
    
    %将所有小于原始数据的时间值对存储在
    %下限值、下限值和所有大于
    %原始数据的上限值
    下限u次=时间i_u文件(tcd i_u文件<tcd平滑i_u文件);
    上界时间=时间i_文件(tcd i_文件>tcd平滑i_文件);
    下限u值=tcd i_u文件(tcd i_u文件<tcd平滑i_u文件);
    上限u值=tcd i_u文件(tcd i_u文件>tcd平滑i_u文件);
    
    %翻转数组顺序以构造可填充的闭合区域
    x=[上限_次;翻转(下限_次)]
    y=[上限值;翻转(下限值)]
    
    填充(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);
    < /代码> 
    
    

    此代码段针对索引指示的多个文件执行。信心水平被很好地填充,如这张放大的单线图所示:

    但是,由于某些原因,所有行的结尾都与beginned连接,如下两个图所示:

    图的右端是这样的:

    我无法用我的手来处理这些返回的填充区域。. 在我的例子中,我是这样实现的:

    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.信心水平被很好地填充,如这张放大的单线图所示:

    Zoomed in image of line with confidence interval

    但是,由于某些原因,所有行的结尾都与beginned连接,如下两个图所示:

    Full plot

    图的右端是这样的:

    Right end zoomed in

    我不知道该如何处理这些返回的填充区。

    1 回复  |  直到 6 年前
        1
  •  2
  •   Brice    6 年前

    使用水平翻转 fliplr 和垂直连接 ; 好像是错了 X=[upper_bound_times; fliplr(lower_bound_times)];

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

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

    如果是行向量,则应使用水平连接 , :

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