How to Plot Particles and Calculate Spherical Harmonics in MATLAB?

In summary, the conversation discusses using MATLAB to visualize data for particle positions in 3D space. The individual is looking for a simple way to plot the particles and mentions the function "streamParticles" but is unsure if it is the right one. However, they later figure out the solution which involves using the function "plot3" and specifying arrays of coordinates. The conversation then shifts to another question about finding the spherical harmonics component of a point in MATLAB, which involves expanding the points in a series of Y_l_m (r_i).
  • #1
JoAuSc
198
1
I have data for the positions of particles in 3D space and I'm trying to use MATLAB in order to visualize it. How do I plot little balls in 3D? The only function I can find at the minute is streamParticles but I'm looking for something simpler.

EDIT: Nevermind, I figured it out. You simply do plot3(x,y,z,'.'), where x, y, and z are arrays of coordinates.


I do have another question, though. How do you find the spherical harmonics component of a point in MATLAB? In other words, if you have a set of points [tex]r_i[/tex], how would you find [tex]Y_l_m (r_i)[/tex]?
 
Last edited:
Physics news on Phys.org
  • #2
You need to expand the points in a series of [tex]Y_l_m (r_i)[/tex]. It is a fairly straightforward proceedure to do so.
 
  • #3


To plot particles in 3D space in MATLAB, you can use the plot3() function as mentioned. This will plot small dots at the specified coordinates. If you want to plot spheres instead of dots, you can use the sphere() function and specify the center coordinates and radius for each particle.

As for finding the spherical harmonics component of a point, you can use the spharm() function in MATLAB. This function takes in the coordinates and the desired degree and order of the spherical harmonic and returns the corresponding value. You can also use the sph2cart() function to convert the spherical coordinates into cartesian coordinates, which can then be used with the plot3 function to plot the points.
 

1. How do I plot particles in MATLAB?

To plot particles in MATLAB, you can use the "scatter" function. This function takes in the x and y coordinates of your particles and plots them as individual points on a graph. You can also customize the appearance of the particles by adjusting the size, color, and shape of the points.

2. Can I plot particles in 3D using MATLAB?

Yes, you can plot particles in 3D using the "scatter3" function. This function works similar to the "scatter" function, but it takes in three sets of coordinates (x, y, z) to plot particles in a 3D space. You can also customize the appearance of the particles in 3D.

3. How can I animate particles in MATLAB?

You can animate particles in MATLAB by using the "plot" function in a loop. Each iteration of the loop will update the positions of the particles, creating the illusion of movement. You can also add other elements to your animation, such as a time variable or changing colors.

4. Is there a way to add labels or annotations to my particle plot in MATLAB?

Yes, you can add labels and annotations to your particle plot in MATLAB using the "text" function. This function allows you to add text to specific points on your graph, such as labeling individual particles or adding a title to your plot.

5. Can I save my particle plot as an image in MATLAB?

Yes, you can save your particle plot as an image in MATLAB by using the "saveas" function. This function allows you to specify the file format (such as PNG or JPEG) and the file name for your saved image. You can also adjust the resolution and size of the image before saving.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
827
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
11
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
Back
Top