Dear everyone,
I would like to ask you about contour plot or suitable tools for representing external data.
Enclosed is my "eField_Sample.txt" data, which include a electric field distribution on an z-plane.
In the file, 3 components of the E-filed are save in complex numbers form. Therefore, the amplitude should be E_total = abs (Ex + Ey+ Ez)
Here what I have tried so far in the Matlab
simData = importdata('eField_sample.txt'); % import data
x_val = simData.data(:,1); % x-coordinate
y_val = simData.data(:,2); % y-coordinate
z_val = simData.data(:,3); % z-cooridnate
E_x = complex(simData.data(:,4),simData.data(:,5)); % complex values of Ex
E_y = complex(simData.data(:,6),simData.data(:,7)); % complex values of Ey
E_z = complex(simData.data(:,8),simData.data(:,9)); % complex values of Ez
[X,Y] = meshgrid(x_val, y_val); % create a matrix of 2 coordinates
[Ex,Ey] = meshgrid(E_x, E_y); % create a matrix of 2 equivalen E-fields, I do not know how to include the Ez components
Eabs_xy = abs(Ex + Ey); % calculate the magnitude of the total field
contourf(X,Y,20*log(Eabs_xy)); %plot
The figure is plotted in dB scale to compare with output from my simulation. I included an example of the E-field from my simulation for comparison. Well they do not look similar to each other.
Could anyone help me how to solve this problem?
Thank you very much,
,

 Akzeptierte Antwort

KSSV
KSSV am 15 Jan. 2021
Bearbeitet: KSSV am 15 Jan. 2021

0 Stimmen

simData = importdata('eField_sample.txt'); % import data
x_val = simData.data(:,1); % x-coordinate
y_val = simData.data(:,2); % y-coordinate
z_val = simData.data(:,3); % z-cooridnate
E_x = complex(simData.data(:,4),simData.data(:,5)); % complex values of Ex
E_y = complex(simData.data(:,6),simData.data(:,7)); % complex values of Ey
E_z = complex(simData.data(:,8),simData.data(:,9)); % complex values of Ez
%%
nx = length(unique(x_val)) ;
ny = length(unique(y_val)) ;
%
X = reshape(x_val,nx,ny) ;
Y = reshape(y_val,nx,ny) ;
%
Ex = reshape(E_x,nx,ny) ;
Ey = reshape(E_y,nx,ny) ;
Eabs_xy = abs(Ex + Ey); % calculate the magnitude of the total field
contourf(X,Y,20*log(Eabs_xy)); %plot

2 Kommentare

Hai Nguyen
Hai Nguyen am 15 Jan. 2021
Dear KSSV,
Great!! many thanks.
You miss the z-component but I included it in my code. Looks amazing.
Greetings,
KSSV
KSSV am 15 Jan. 2021
Use pcolor instead of contourf.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Gefragt:

am 15 Jan. 2021

Kommentiert:

am 15 Jan. 2021

Community Treasure Hunt

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

Start Hunting!

Translated by