我有一个用 plotmatrix 创建的子图矩阵,并且想为每个子图添加最适合的行,但不知道该怎么做。有没有办法将 polyfit 分别应用于每个子图?
这是迄今为止我所拥有的简化示例
x = randn(50,3);
y = x*[-1 2 1;2 0 1;1 -2 3;]';
[H,AX,BigAx,P,PAx] = plotmatrix(x,y);
我想我需要学习如何以某种方式对子图矩阵进行索引。
我有一个用 plotmatrix 创建的子图矩阵,并且想为每个子图添加最适合的行,但不知道该怎么做。有没有办法将 polyfit 分别应用于每个子图?
这是迄今为止我所拥有的简化示例
x = randn(50,3);
y = x*[-1 2 1;2 0 1;1 -2 3;]';
[H,AX,BigAx,P,PAx] = plotmatrix(x,y);
我想我需要学习如何以某种方式对子图矩阵进行索引。
我不知道如何覆盖由 生成的现有矩阵plotmatrix
,但您可以自己创建矩阵并使用以下结果覆盖每个子图polyfit
:
figure;
x = randn(50,3);
y = x*[-1 2 1;2 0 1;1 -2 3;]';
degree=4;
rows = size(x,2);
cols = size(y,2);
for k=1:rows
for m=1:cols
subplot(rows, cols, (k-1)*rows+m);
hold all;
scatter(x(:,k),y(:,m),'.');
p = polyfit(x(:,k),y(:,m),degree);
x_p = linspace(min(x(:,k)), max(x(:,k)));
y_p = polyval(p,x_p);
plot(x_p, y_p,'LineWidth',2);
hold off;
end
end