Matlab: what is the right 3D plotting function for my code?

In summary, the conversation discusses using the meshgrid and surf functions to plot a 3D graph of y and O for a given range of x values, which can be achieved by using a loop and changing the values of x and Omega.
  • #1
Romik
14
0
Hi all, I have a simple question about 3D plotting.

Consider this simple loop, which provides y and O for any x. and I am able to plot y vs O for given x.

for Omega=0:.01:5

y(i)=(x*Omega^2);

O(i)=Omega;

i=i+1;

end

now consider I want to change the value of x, for x=0:.1:3 and plot the group of y's and O's in one plot.(y~O~x) which one of the 3D plot functions are right for this purpose and what will be the code?

I would appreciate you time and help,

Romik
 
Physics news on Phys.org
  • #2
You'll probably want to use meshgrid and surf. Something like:
Code:
x = [color=#008000]linspace[/color](0, 3, 100);
omega = [color=#008000]linspace[/color](0, 5, 100);
[X Omega] = [color=#008000]meshgrid[/color](x, omega);
Y = X [color=#666666].*[/color] Omega [color=#666666].^[/color]2;
surf(X, Y, Omega); [color=#408080][i]% Or whatever order you want to plot...[/i][/color]
 
Last edited:

1. How do I plot a 3D graph in Matlab?

In order to plot a 3D graph in Matlab, you can use the "plot3" function. This function takes in three vectors, representing the x, y, and z coordinates of the data points, and creates a 3D line plot.

2. What is the difference between "plot3" and "scatter3" in Matlab?

The main difference between these two functions is the type of graph they produce. "Plot3" creates a line graph, while "scatter3" creates a scatter plot. Additionally, "plot3" requires three input vectors, while "scatter3" only requires two input vectors.

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

Yes, you can customize the appearance of your 3D plot in Matlab by using various optional parameters in the "plot3" function. These parameters allow you to change the color, style, and size of the plotted data points and lines.

4. How do I add a title and labels to my 3D plot in Matlab?

You can add a title and labels to your 3D plot by using the "title", "xlabel", "ylabel", and "zlabel" functions in Matlab. These functions allow you to specify the text for the title and labels, as well as customize their appearance.

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

Yes, you can save your 3D plot as an image in Matlab by using the "saveas" function. This function allows you to specify the file format (such as png or jpg) and the file name for your saved image.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
11
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
993
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
2K
Back
Top