MATLAB: Plane fit (z=ax+by+c) to 3D point data

least squrareMATLABplane fitting

Hi,
I have step plot (attached) and I want to fit a plane on the lower terrace of it. Excel file of point cloud is attached as well. Data represent in file is N-by-3 numeric data and each column corresponds to x, y and z. Could anyone please help me out how to fit the plane to the lower terrace?

Best Answer

Assuming that your data is N-by-3 numeric array, say yourData, and each column corresponds to x, y and z, the following code can generate a, b and c for fitting plane (z = ax + by + c).
% Assuming that yourData is N-by-3 numeric array
B = [ones(N,1), yourData(:,1:2)] \ yourData(:,3);
Where a = B(2), b = B(3) and c = B(1).