adding a regression area to a 3d plot

15 views (last 30 days)
Mostafa
Mostafa on 13 Aug 2014
Edited: Amir on 13 Aug 2014
First of all I would like to mention that I don't know much about matlab programming but I'm trying to do something that I think is simple.
I created a 3d scatterplot using the "plots" tab. My data set has 3 arrays; x, y, and z.
That was easy enough. Now I would like to add a best fit surface area to the plot. How do I do that? I tried following other questions that were asked but I wasn't able to understand the code. I am not creating a function. I am just using using the command window with the x,y, and z arrays in work space.
Please help!
Thanks!

Answers (1)

Amir
Amir on 13 Aug 2014
Edited: Amir on 13 Aug 2014
Hi Mostafa. Try this code:
x=5*rand(1,1000); % 1000 random number between 0 and 5
x=x'; % transpose (row to vector)
y=sin(x)/3;
z=x.^2-y.^2 + sin(x.*y) + 5 * rand(size(x)); % rand for some noise
f = fit( [x, y], z, 'poly23' );
plot(f, [x,y], z);
Hope this helps you.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!