Plot electric field in plane
8 views (last 30 days)
the png file shows the magnitude of an electric field in a plane, which was calculated by means of an electromagnetic field solver. I exported the field data to a txt file (see attachement), as I want to plot these data in Matlab. How can I create a plot, whose result looks similar to the attached png file?
Thank you very much for your help!
Star Strider on 26 Jul 2022
Try this —
M1 = readmatrix('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1077575/data.txt')
[U1,ix1] = unique(M1(:,1));
[U2,ix2] = unique(M1(:,2));
% [U3,ix3] = unique(M1(:,3))
n = numel(U1);
m = numel(U2);
nr = reshape(M1(:,1),n,);
mr = reshape(M1(:,2),n,).';
vr = reshape(M1(:,7),n, ).';
contourf(vr, 100, 'EdgeColor','none')
It does not look exactly like the posted image, however not enough information has been provided to allow anything else. I first tried readtable, however the variables were not named, so I have no idea what variables are to be used or plotted. I just experimented here until I found a way to re-define the vectors as matrices, and then indexed through the columns until I found something that seemed to resemble the posted image.
Obviously, more information would be helpful!
More Answers (1)
Issa on 26 Jul 2022
Elec_F = readmatrix('data.txt') ;
x = Elec_F(:, 1) ;
y = Elec_F(:, 2) ;
z = Elec_F(:, 3) ;
Ef =abs(sqrt((Elec_F(:,4) + 1i*Elec_F(:,5)).^2 + (Elec_F(:, 6) + 1i*Elec_F(:, 7)).^2 + ...
(Elec_F(:, 8) + 1i*Elec_F(:, 9)).^2) );
scatter3(x,y,z,  , Ef,"filled", "square", 'MarkerFaceColor','flat')
ax = gca ;
ax.BoxStyle = "full" ;
Note that with dense data you will get better resolution.