【问题标题】:MATLAB: Curve fitting to scattered data in plotmatrixMATLAB:曲线拟合到 plotmatrix 中的分散数据
【发布时间】:2016-10-06 05:15:48
【问题描述】:

下图是在 MATLAB 中使用[H,AX,BigAx,P] = plotmatrix(x); 创建的。代替非对角线上的散点,是否有可能有一条近似曲线?

【问题讨论】:

    标签: matlab curve-fitting plotmatrix


    【解决方案1】:

    阅读documentation,似乎这个函数只对散点有用,这是有道理的,因为通常矩阵中的点可能会被全部覆盖并且拟合曲线没有意义。也许使用 subplot() (link) 会更合适并允许更多功能?

    【讨论】:

      【解决方案2】:

      使用plotmatrix 创建图后,您可以遍历每个非对角散点图,获取关联的XY 数据、perform the curve fitting,然后是plot the results,如下所示:

      data = randn(50,3);  % Random sample data
      [hScatter, hAxes] = plotmatrix(data);
      
      for index = find(~eye(size(hScatter))).'  % Loop over off-diagonal plots
        X = get(hScatter(index), 'XData');      % Get X data
        Y = get(hScatter(index), 'YData');      % Get Y data
        betas = [ones(numel(X), 1) X(:)]\Y(:);  % Simple linear regression
        xLine = get(hAxes(index), 'XLim');      % Use axes limits for X data
        yLine = betas(1)+xLine.*betas(2);       % Compute regression line
        line(hAxes(index), xLine, yLine, 'Color', 'r');  % Plot red regression line
      end
      

      这是结果图:

      【讨论】:

        猜你喜欢
        • 2019-01-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-03-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多