I am really struggling to fit a mean plane to point cloud data in Matlab (least square). I've tried numerous other approaches as exemplified on this page, but get the same mean plane as in the image, which obviously is terribly wrong. Do you have any idea what may be wrong?
load('xyz.mat'); %//load the variable 'a' that is 44005x3 in size
x = a(:,1);
y = a(:,2);
z = a(:,3);
%//Calculate coeffs for a mean plane for points x,y,z
%//eq: xh(1) xh(2)*x + xh(3)y + - z = 0
[X,Y] = meshgrid(min(x):10:max(x),min(y):10:max(y));
A = [ones(length(x),1) x y ];
xh = A'*A\(A'*z);
Zp = X.*(xh(2)) + Y.*xh(3) + xh(1);
%//plot mean plane
mesh(X,Y,Zp,'EdgeColor','Black');
hold on;
%//plot pointcloud
pcshow(a)
hold off;