如何在Matlab中绘制具有3个变量的线性模型的数据? [英] how to plot the data for linear model with 3 variables in matlab?

查看:375
本文介绍了如何在Matlab中绘制具有3个变量的线性模型的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

To plot the data in 3D plane for this model: y = a + a1*x1 + a2*x2 I do like this, the figure is shown in this website (http://kr.mathworks.com/help/stats/regress.html) , x1, x2, and y denote respectively vectors X, Y, and 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? 我使用以下代码获取线性模型

My question is how can I plot the model with 3 variables in 3D: y = a + a1*x1 + a2*x2 + a3*x3 ? I used the below code to get the linear model

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

p1,a2,a3 <-> X2向量.

a1,a2,a3 <-> X2 vector.

推荐答案

我将基于三个输入(y,x1,x2)创建一个函数来求解方程式(functionSolver) 定义您关心的区域的网格

I would create a function to solve the equation (functionSolver) based on three inputs (y,x1,x2) Define a grid of the region you care about

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.

这篇关于如何在Matlab中绘制具有3个变量的线性模型的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆