adding a regression area to a 3d plot

5 次查看(过去 30 天)
Mostafa
Mostafa 2014-8-13
编辑: Amir 2014-8-13
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!

回答(1 个)

Amir
Amir 2014-8-13
编辑:Amir 2014-8-13
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.

类别

Help CenterFile Exchange 中查找有关 Scatter Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by