How to plot streamline of electric field from a column of data?
Show older comments
Hi. I have a column of data and I want to plot it in MATLAB such that the color map show the intensity, as showin the attached figure?

8 Comments
Chuguang Pan
on 10 Sep 2025
Bacha Munir
on 10 Sep 2025
Hi @Bacha Munir
Could you briefly explain how to interpret the table? Specifically, which columns represent the Cartesian coordinates and which columns represent the directional components in the Electric Field?
T = readtable('Column of data.txt', VariableNamingRule="preserve")
@Bacha Munir, Another point to consider is that the quiver() function suggested by @Chuguang Pan may be unsuitable for plotting streamlines. From your image, the "arrow-like" objects are actually referred to as streamlines in physics, which visualize the dynamic flow of particles or substances. To distinguish them, an arrow in MATLAB typically has its arrowhead at the tip, and its shaft (arrow line) is straight.
[X, Y] = meshgrid(0:6, 0:6);
U = 0.25*X;
V = 0.5*Y;
quiver(X, Y, U, V, 0)
Chuguang Pan
on 10 Sep 2025
@Bacha Munir. After querying the documentation, I find there is a streamslice function for ploting streamlines. I think this function is more suitable for your requirement.
Bacha Munir
on 11 Sep 2025
@Bacha Munir, Thank you for your reply. But I do not quite understand. Let us ignore the NaN values and consider the 7th row as an example. The coordinates are (4.3975, 2.3949). Since the 3rd column is labeled "streamline," what does the value of "0" mean?
You may use the streamslice() function as suggested by @Chuguang Pan. However, to produce color-gradient streamlines that indicate the intensity of the electric field (as represented by the 4th column data), you might try the approach recommended by @Bjorn Gustavsson.
[x, y] = meshgrid(-1:1); % generate coordinates in the grid
u = 2.*x.*y; % horizontal component of the velocity vector
v = y.^2 - x.^2; % vertical component of the velocity vector
streamslice(x, y, u, v)
title('Magnetic Field')
axis square
axis([-1, 1, -1, 1])
Bacha Munir
on 11 Sep 2025
Accepted Answer
More Answers (0)
Categories
Find more on Vector Fields in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
