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

63 次查看(过去 30 天)
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 个评论
Sam Chak
Sam Chak 2025-9-11,5:52
@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])

请先登录,再进行评论。

采纳的回答

Bjorn Gustavsson
Bjorn Gustavsson 2025-9-10,7:59
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Vector Fields 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by