MATLAB 3D Plotting: Tutorial & Help

  • Context: MATLAB 
  • Thread starter Thread starter elham
  • Start date Start date
  • Tags Tags
    3d Matlab Plotting
Click For Summary
SUMMARY

The discussion focuses on converting 2D plotting code in MATLAB to 3D plotting. The original code utilizes the plot function for 2D visualization of costs associated with particles. To achieve a 3D plot, users must introduce a third variable, which can be visualized using functions such as surf, surfc, contour, and plot3. The discussion emphasizes the importance of defining the type of plot and the three variables required for effective 3D representation.

PREREQUISITES
  • Familiarity with MATLAB syntax and functions
  • Understanding of 2D plotting concepts in MATLAB
  • Knowledge of 3D data visualization techniques
  • Ability to manipulate matrices in MATLAB
NEXT STEPS
  • Learn how to use surf for 3D surface plots in MATLAB
  • Explore the plot3 function for 3D line plots
  • Investigate contour and surfc for contour plots in 3D
  • Review the MATLAB documentation on 2D and 3D plotting techniques
USEFUL FOR

Data scientists, engineers, and researchers who need to visualize multidimensional data in MATLAB, particularly those transitioning from 2D to 3D plotting.

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 ·
Replies
8
Views
3K
  • · Replies 9 ·
Replies
9
Views
5K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
2
Views
3K