Surf function problem
显示 更早的评论
I have a problem drawing a surface for a regression.
I have 3 vectors Y, X1, X2 and I have estimated the multiple linear regression: Y = c + a*X1 + b*X2 + u
I would like to draw the graph of this regression: Y = c + a*X1 + b*X2 + u using a MATLAB plot-graph.
I have tried the 'surf' function but I get this error 'Matrix dimensions must agree'.
I have done these things so far.
- Estimate the coefficients (c,a,b).
- Make a new serie [f=Y(estimated)], using the estimated coefficients (c,a,b). New serie: f = c + a*X1 + b*X2
- Use the 'surf' function. surf(X1,X2,f)
Can someone help me? I can’t understand what I am doing wrong.
PS: I use MATLAB 6.5*
采纳的回答
更多回答(6 个)
Sean de Wolski
2011-1-26
I.e. the known Y-values that you used for your regression? How about:
scatter3
or
plot3
to overlay them on your surface?
Sean de Wolski
2011-1-26
Yes.
figure;
surf(...)
hold on
scatter3(...)
strat
2011-1-26
0 个投票
1 个评论
Sean de Wolski
2011-1-26
So you overwrote the original X1,X2 with the meshgrid X1,X2?
The call to scatter3 should be with the _original_ X1,X2 used for your regression and Y
scatter3(X1orig,X2orig,Y)
类别
在 帮助中心 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!