How to plot streamline of electric field from a column of data?

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

You can use quiver function to plot vector field.
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")
T = 980×6 table
% Version: COMSOL 6.2.0.290 Var5 Var6 ______ ________ __________ _________ ____________ _____________ NaN NaN NaN 10 {'2025,' } {'10:04' } NaN NaN 2 NaN {0×0 char } {0×0 char } NaN NaN 9.0636e+05 NaN {0×0 char } {0×0 char } NaN NaN 2 NaN {0×0 char } {0×0 char } NaN NaN NaN NaN {0×0 char } {0×0 char } NaN NaN NaN NaN {'Electric'} {'potential'} 4.3975 2.3949 0 1.4465 {0×0 char } {0×0 char } 4.3975 2.3952 0 1.4465 {0×0 char } {0×0 char } 4.3975 2.3954 0 1.4465 {0×0 char } {0×0 char } 4.3975 2.3956 0 1.4465 {0×0 char } {0×0 char } 4.3975 2.3958 0 1.4465 {0×0 char } {0×0 char } 4.3974 2.396 0 1.4465 {0×0 char } {0×0 char } 4.3974 2.3963 0 1.4464 {0×0 char } {0×0 char } 4.3974 2.3965 0 1.4464 {0×0 char } {0×0 char } 4.3974 2.3967 0 1.4464 {0×0 char } {0×0 char } 4.3974 2.3969 0 1.4464 {0×0 char } {0×0 char }
@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)
@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.
@Sam Chak you are right that the quiver commond is not suiatble. I have checked. In the data column, the first two columns are the x and y coordinates, the third one is the streamline, and the final one is the electric potential. Could you please plot in the MATLAB to create the given figure?. Also please post here for me the MATLAB code. Thank you.
@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])

Sign in to comment.

 Accepted Answer

So you have electrical potential along a nearly straight curve. If that's all you have it becomes tricky to understand what you're asking for, what do you mean by intensity? If you want to plot a coloured line there are a bunch of contributions on the file exchange:
cline (1), cline (a), cline (I) and at least one 3-D variant: plot 3-D-color-line.
You can either plot the potential along that curve directly:
cline(Epot(:,1),...
Epot(:,2),...
zeros(size(Epot(:,2))),...
Epot(:,4),turbo)
Where I've saved your columns of data into the variable Epot. My version of cline is a slightly modified version of one of those linked above.
...or if you want something like potential difference in between points:
cline(Epot(1:end-1,1),...
Epot(1:end-1,2),...
zeros(size(E_pot(1:end-1,2))),...
Epot(1:end-1,4),turbo)
You would have to check the input arguments to the cline-function you decide to use.
HTH

More Answers (0)

Categories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!