how to plot the data for linear model with 3 variables in matlab?

爷,独闯天下 提交于 2019-12-08 11:35:25

问题


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)

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);

a1,a2,a3 <-> X2 vector.


回答1:


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.


来源:https://stackoverflow.com/questions/33387195/how-to-plot-the-data-for-linear-model-with-3-variables-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!