Contour plot for the external data

3 次查看(过去 30 天)
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,
,

采纳的回答

KSSV
KSSV 2021-1-15
编辑:KSSV 2021-1-15
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 个评论
Hai Nguyen
Hai Nguyen 2021-1-15
Dear KSSV,
Great!! many thanks.
You miss the z-component but I included it in my code. Looks amazing.
Greetings,
KSSV
KSSV 2021-1-15
Use pcolor instead of contourf.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by