MATLAB MATLAB 3D Plotting: Tutorial & Help

AI Thread Summary
To convert a 2D plot in MATLAB to a 3D plot, a third variable is required to represent the z-axis values. The discussion suggests using functions such as surf, surfc, contour, or plot3 for 3D plotting. Users are encouraged to clarify the type of plot desired and identify the three variables needed for the 3D representation. A link to MATLAB's documentation on 2D and 3D plots is provided for further guidance.
elham
Messages
1
Reaction score
0
Hi Friends,
The code below is for 2D ploting in Matlab, I want to change it in 3D, please if anyone know how to do this.let me know
thanks in advancefigure(1);
popcosts=[pop.Cost];
repcosts=[rep.Cost];
plot(popcosts(1,:),popcosts(2,:),'b.');
hold on;
plot(repcosts(1,:),repcosts(2,:),'r*');
hold off;
legend('Normal Particles','Repository Particles');
xlabel('f_1');
ylabel('f_2');
 
Last edited by a moderator:
Physics news on Phys.org
What is your z variable? You need a third variable of values to plot in 3D.

For example,

surf(popcosts(1,:),popcosts(2,:),popcosts(3,:))

You could also use surfc, contour, plot3, and countless other functions for 3D plotting. Answer the below questions, and then click the following link:

http://www.mathworks.com/help/matlab/2-and-3d-plots.html

1. What kind of plot do you want?
2. What are your 3 variables?
 

Similar threads

Replies
8
Views
2K
Replies
9
Views
5K
Replies
2
Views
3K
Replies
2
Views
2K
Replies
4
Views
3K
Replies
5
Views
2K
Replies
1
Views
2K
Back
Top