Computational Science Stack Exchange is a question and answer site for scientists using computers to solve scientific problems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am currently working on my bachelor thesis, where I am calculating trajectory of electrons and ions in Hall Effect Ion Thruster. However, to be sure what I am calculating, I need to know how does the electromagnetic field look like.

I already have working code for visualization of electromagnetic field using streamslice, however I would like to take it to the next level.

I have created coordinates $x,$ $y$ and $z$ through meshgrid and computated magnetic field, which is set of not really pretty equations. Electric field points only towards the $z$ direction.

Here is the snappet of code that is generating picture below:

% Magnetic field
plot_field = streamslice(x,y,z,Bx,By,Bz,0.02,0.02,0);

% Electric field
hold on;
hold off;

% Plot of discharge chamber
[x_ch, y_ch, z_ch] = cylinder(0.4,40);
z_ch(1,:) = -0.2;
z_ch(2,:) = 0.2;

hold on;
plot_ch = surf(x_ch,y_ch,z_ch);
hold off;

This code generates the following,

Plot of magnetic field line slices


I would like to create streamslice of the magnetic field in various degrees slope (let's say $45$), so I could see how does the field looks like not only when intersecting magnetic dipoles, but also in other locations. That would be great for study of particle motion.

share|improve this question

migrated from May 7 '13 at 20:54

This question came from our site for active researchers, academics and students of physics.

up vote 1 down vote accepted

It is possible to draw a streamslice slicing using non-planar or at arbitrary angle. You can use rotate command to rotate your slicing plane(s). Your plot_field object can be modified by adding several lines

slicing = surf(linspace(-1,1,10),linspace(-1,1,10),zeros(10));
% third input: rotating angle
% second input: the vector to which you are rotating your data with respect
xs = get(slicing,'XData');
ys = get(slicing,'YData');
zs = get(slicing,'ZData');
plot_field = streamslice(x,y,z,Bx,By,Bz,xs,ys,zs);

Also contourslice is another my own favorite to visualize electromagnetic field:

If you know how to use VTK, then you can export your 3D vector data to a vtk file using:

Then you could use software like Paraview to visualize vector field as you like, for example, slicing at $45^{\circ}$ degree of the box like you said (I used the data of my own from a dielectric with a cavity Maxwell pde):


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.