【发布时间】:2016-10-06 05:15:48
【问题描述】:
【问题讨论】:
标签: matlab curve-fitting plotmatrix
【问题讨论】:
标签: matlab curve-fitting plotmatrix
阅读documentation,似乎这个函数只对散点有用,这是有道理的,因为通常矩阵中的点可能会被全部覆盖并且拟合曲线没有意义。也许使用 subplot() (link) 会更合适并允许更多功能?
【讨论】:
使用plotmatrix 创建图后,您可以遍历每个非对角散点图,获取关联的X 和Y 数据、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
这是结果图:
【讨论】: