MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today**New to MATLAB?**

Asked by kanai
on 31 Jul 2013

I would like to to know the equation of a plane of best fit using a set of 20 xyz coordinates. I can do it using the SF tool but I would like to know the code to run for my data to get it in the command bar and without using the cumbersome SFtool

Once I have the equation I would like to find the point on the plane where a line crosses it. This line would be in a parametric format.

Many thanks kg

*No products are associated with this question.*

Answer by Tom Lane
on 1 Aug 2013

If you set up a matrix X with three columns containing your x values, your y values, and a column of twenty ones, and set up a Y column vector containing your z values, then

b = X\y

will return the least-squares coefficient estimates. This is the least squares solution in the sense of minimizing the errors in the z direction.

kanai
on 3 Aug 2013

Thanks for getting back to me. I am a beginner in matlab so I apologise for silly questions

So far I have my data in a 3x20 database on excel. I have imported this to matlab. I have created a column between the y data and the z data and filled it with ones.

I have created a variable for column 1-x, column 2-y, column 4-z (right click and created variable labelling it x/y/z data)

Where do I go from here?

many thanks

Tom Lane
on 3 Aug 2013

If you have x,y,z as column vectors of the same length, then

b = [ones(size(x)),x,y]\z

will estimate three coefficients for predicting z: the intercept, the multiplier of x, and the multiplier of y.

## 0 Comments