MATLAB 3D Plotting: Tutorial & Help

In summary, the conversation is about changing a 2D plot in Matlab to a 3D plot. The person is asking for help in finding a way to plot in 3D and provides an example of using the surf function. They also mention other functions that can be used for 3D plotting. The conversation ends with a link to a website for further guidance.
  • #1
elham
1
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
  • #2
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?
 

Related to MATLAB 3D Plotting: Tutorial & Help

1. What is MATLAB 3D plotting?

MATLAB 3D plotting is a tool in the MATLAB software that allows you to create three-dimensional representations of data and functions. This can be useful for visualizing complex data, analyzing trends, and understanding relationships between variables.

2. How do I create a 3D plot in MATLAB?

To create a 3D plot in MATLAB, you can use the "plot3" function. This function takes in three arrays of data representing the x, y, and z coordinates of your points. You can also use the "surf" function to create a surface plot, or the "scatter3" function to create a 3D scatter plot.

3. Can I customize the appearance of my 3D plot?

Yes, you can customize the appearance of your 3D plot in MATLAB. You can change the color, size, and style of the points, lines, and surfaces in your plot. You can also add labels, titles, and legends to make your plot more informative.

4. How can I add multiple data sets to a single 3D plot?

To add multiple data sets to a single 3D plot, you can use the "hold on" command. This will allow you to plot multiple sets of data on the same plot. You can also use the "subplot" function to create multiple plots within the same figure.

5. Is there a way to save my 3D plot as an image or video?

Yes, you can save your 3D plot as an image or video in MATLAB. You can use the "print" command to save your plot as an image in a variety of formats, such as PNG or JPEG. You can also use the "movie" function to create a video of your 3D plot, which can be saved as an AVI file.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
399
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
Back
Top