如何在matlab中用3个变量绘制线性模型的数据?

时间:2015-10-28 09:23:57

标签: matlab regression linear-regression linear

为此模型绘制3D平面中的数据:y = a + a1 * x1 + a2 * x2 我喜欢这个,这个数字显示在这个网站上(http://kr.mathworks.com/help/stats/regress.html),x1,x2和y分别表示向量X,Y和Z.

scatter3(x1,x2,y,'filled')
hold on
x1fit = min(x1):100:max(x1);
x2fit = min(x2):10:max(x2);
[X1FIT,X2FIT] = meshgrid(x1fit,x2fit);
YFIT = b(1) + b(2)*X1FIT + b(3)*X2FIT + b(4)*X1FIT.*X2FIT;
mesh(X1FIT,X2FIT,YFIT)
xlabel('Weight')
ylabel('Horsepower')
zlabel('MPG')
view(50,10)

我的问题是如何在3D中用3个变量绘制模型:y = a + a1 * x1 + a2 * x2 + a3 * x3? 我使用下面的代码来获得线性模型

X2 = [ImageSize Resolution PSNR];
lm3 = regress(K_Number, X2);

a1,a2,a3 - < - > X2矢量。

1 个答案:

答案 0 :(得分:0)

我会根据三个输入(y,x1,x2)创建一个求解方程(functionSolver)的函数 定义您关心的区域的网格

y = -100:1:100;
x1 = -50:0.05:25;
x2 = 10:0.5:100;
(outx, outy, outz) = functionSolver(x1,x2,y); However you defined this
plot3(outx, outy, outz); This will plot the output as defined in your grid.
相关问题