【问题标题】:How to add a regression line to a scatter plot in MATLAB如何在 MATLAB 中将回归线添加到散点图中
【发布时间】:2016-11-01 17:43:00
【问题描述】:

我正在尝试将回归线添加到 MATLAB 中的绘图上。 这是我的代码:

errorbar(x,y,SEM,'o')
hold on % Retains current plot while adding to it
scatter(x,y)
title('The Effect of Distance Between Images on the Flashed Face         Distortion Effect','FontSize',14); % Adds title
xlabel('Distance (Pixels)','FontSize',12); % Adds label on the x axis
ylabel('Average Distortion Rating','FontSize',12); % Adds label on the y axis
hold off

这是我的回归代码: mdl = fitlm(x,y,'线性');

谁能告诉我如何将两者结合起来,以便我得到情节上的回归线? 我在 Windows 上的 MATLAB 上使用 psychtoolbox。 谢谢!

【问题讨论】:

  • 我猜你也有曲线拟合工具箱?您可以简单地在hold off 之前添加带有右轴限制的plot(mdl),它应该可以工作。

标签: matlab regression


【解决方案1】:

在hold off 语句之前,添加以下行:

xf = [min(x), max(x)];
plot(xf, polyval(polyfit(x,y,1), xf));

您可能希望使用设置线条样式的补充参数来装饰您的 plot 调用,并且不需要额外的工具箱。

【讨论】:

    猜你喜欢
    • 2015-01-27
    • 1970-01-01
    • 2012-06-27
    • 1970-01-01
    • 2016-02-24
    • 1970-01-01
    • 2013-05-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多