You are on page 1of 1

MATLAB code for plotting 3D patterns

% The following code is an example of how to plot a


% 3-D pattern. For simplicity, it plots the 3-D pattern of a short
% dipole oriented along the Z-axis (E = sin(theta))
i=1;
deltatheta = 0.2;
deltaphi = 1;
for (phi = 0:deltaphi:360)
j=1;
for(theta = 0:deltatheta:360)
E(i,j) = sin(theta*pi/180);
j=j+1;
end
i=i+1;
end
phi = (0:deltaphi:360)*pi/180;
theta= (0:deltatheta:360)*pi/180;
[PHI,THETA] = meshgrid(phi,theta);
R = abs(E)';
X=R.*sin(THETA).*cos(PHI);
Y=R.*sin(THETA).*sin(PHI);
Z=R.*cos(THETA);

% Convert from spherical to Cartesian


% coordinates

mesh(X,Y,Z)
xlabel ('X')
ylabel('Y')
zlabel ('Z')
% When you run this code in MATLAB, you will get the following 3-D
% pattern

% You can change the viewpoint using view

You might also like