MATLAB: Surf function problem

linearplotregressionsurface

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.
  1. Estimate the coefficients (c,a,b).
  2. Make a new serie [f=Y(estimated)], using the estimated coefficients (c,a,b). New serie: f = c + a*X1 + b*X2
  3. 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*

Best Answer

You'll have to use
meshgrid
to generate your index matrices.
[X1 X2] = meshgrid(1:50);
c = pi;
a = 2;
b = -3;
f = c+a*X1+b*X2;
surf(X1,X2,f)
-Sean