【问题标题】:Unwrapping everything in the same direction朝着同一个方向展开一切
【发布时间】:2014-07-17 19:24:29
【问题描述】:

我昨天问了一个类似的问题,关于如何在使用atan2d 时避免数据“跳跃”。该函数在 -180 到 180 的范围内运行,如下所示:

当一个数字超过 180 时,它会直接变为 -180,从而使线图 very ugly and not intuitive 可以读取。我使用unwrap 来解决这个问题是suggested,我认为确实如此。然而,今天我遇到了一个看起来像这样的图表:

.

跳转是固定的,但在它的位置有一行被翻译到顶部。如果您绘制这三条线,它们会非常接近,就像它们应该的那样(-180 和 180 仍然是同一个位置,就像 atan2d 图表一样)。我希望我的图表能够反映角度的真实情况 - 非常接近。

根据 David K 的要求,这是我用来计算其中一条线的角度的代码。 rec,ret 是一组有序的坐标,recxrecy 分别是它们的 x 和 y 值。然后我将 theta_r 的结果绘制到一个常规图形上。

for i=1:length(recx)
    dy(i,1)=((recy(i)-rety(i)));
    dx(i,1)=((recx(i)-retx(i)));
    sloperight(i,1)=(dy(i)/dx(i));
    theta_r(i,1)=atan2d(dy(i),dx(i));

end
theta_r = 180/pi * unwrap(theta_r * pi/180);

我的问题

如何使展开功能仅在一个方向展开(使所有角度相对于圆上的顺时针方向或逆时针方向)而不是在最近的方向展开?或者我应该使用unwrap 以外的其他东西来使图表看起来不错?

【问题讨论】:

  • 如果您发布制作图表的 MATLAB 代码(包括使用 unwrap 的部分),可能更容易找出问题所在。例如,从文档来看,unwrap 似乎会消除一维数组中的跳跃,但不会消除二维数组的列之间的跳跃。

标签: matlab graph angle atan2


【解决方案1】:

这里有一个想法:在您的数据集中选择一个值,例如,第一“行”数据中的第一个值。将angle0 设置为该值,并为每个数据数组A 创建A 的“调整后”副本,如下所示:wrapTo180(A - angle0) + angle0,并绘制新数据。

请确保对您在一张图表上绘制的所有数据使用相同的 angle0 值。

这种方法可能对某些数据集有其自身的问题(例如,如果角度在足够宽的范围内逐渐增加,这种方法将产生原始数据中不存在的“跳跃”),但是由于您知道数据都围绕一个角度值(模 360 度)聚集,它应该适合您的图表。

【讨论】:

    【解决方案2】:

    当我离开电脑时,我没有回答这个问题,因此今天早上nerdsniped我自己。

    以下是将 David K 的答案付诸实践的一些代码。使用提供的随机种子来保证一个体面的例子。注释该行以每次查看不同的示例。

    %Seed maintenance
    %    This seed seems to demonstrate the desired behavior. Comment this out
    %    to see multiple examples
    rng(523205203)
    
    %Parameters
    N = 500;
    commonRate = 10;
    independentRate = 2;
    nSeries = 4;
    
    %Some random data
    common = randn(N*2,1)*commonRate;
    independent = randn(N*2,nSeries)*independentRate;
    
    %Build up some interesting data series
    data = cumsum(bsxfun(@plus,common, independent), 1);
    data = data((N+1):end, :);
    
    %Setup observed data, observing modulated data
    observedData = mod(data, 360)-180;
    
    %Utility functions
    %    Basic unwrapping, in deg
    unwrap_deg            = @(x) unwrap(x/180*pi)*180/pi;           
    %    Unwrapping, using an arbitrary offset, in deg
    unwrapToValue_deg     = @(x, value) unwrap_deg(x-value)+value;  
    %    Basic unwrapping, in dim 1, after adjusting columns based on row 1
    equalizeAndUnwrap_deg = @(x) unwrap_deg(...
        bsxfun(@plus, ...
        unwrapToValue_deg(x(1,:),x(1,1)) - x(1,:), ...   %Per column, add the difference ebtween row 1 and the unwrapped row 1
        observedData)...    
        );
    
    %Use functions to correct observred data
    unwrappedObservedData = unwrap_deg(observedData);
    equalizedUnwrappedObservedData = equalizeAndUnwrap_deg(observedData);
    
    %Plot
    figure(2932323)
    subplot(311)
    plot(observedData,'.')
    subplot(312)
    plot(unwrappedObservedData,'.')
    subplot(313)
    plot(equalizedUnwrappedObservedData,'.')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多