MATLAB: Thread Subject: Error :”In an assignment A(I) = B, the number of elements in B and I must be the same.”

3d antenna pattern3d plotarray factor

I have a problem with calculating Ep(I). Any suggestion how to sole this problem?
clear all;
% element numbers N, wavenumber B
N = input ('Enter the Number of Array Elements : ') ;
lambda = input ('Enter the Value of Lambda (c/f) : ') ;
B =(2*pi/lambda);
% Magnitude, Phase, X,Y,Z coordinate
for I = 1 : N
Current = I
An(I) = input ('Enter the Magnitude of the Current : ') ;
Jp(I) = input ('Enter the Phase of the Current : ') ;
Xn(I) = input ('Enter the Position of Element on X-axis : ') ;
Yn(I) = input ('Enter the Position of Element on Y-axis : ') ;
Zn(I) = input ('Enter the Position of Element on Z-axis : ') ;
end
%azimut--> 0<Phi<360, elevation--> 0<Theta<180
Phhi = (0:1:360)*2*pi/180;
Thheta = (0:1:180)*2*pi/180;
[PHI,THETA] = meshgrid(Phhi,Thheta);
%R=[];
% calculate the array factor
for I = 1:N
Ep(I)= B.*((Xn(I).*cos(PHI).*sin(THETA))+(Yn(I).*sin(THETA).*sin(PHI))+(Zn(I).*cos(THETA)));
R(I)= An(I).*exp(1i.*(Ep(I)+(Jp(I).*pi/180)));
end
h(THETA,PHI) = sum(R);
AF(THETA,PHI) = abs(h(THETA,PHI));
%plot the array factor
X = AF.*sin(THETA).*cos(PHI);
Y = AF.*sin(THETA).*sin(PHI);
Z = AF.*cos(THETA);
figure(2);
mesh(X,Y,Z); %display
%surf(X,Y,Z) %colored faces
Best regards, Tadej

Best Answer

I already described to you before why you are getting this error: you are trying to fit a vector or higher dimensional data in to the scalar Ep. At the time I pointed out which variables were vectors. You should be able to calculate from that analysis what size and shape of value is being calculated in each iteration of the loop. When you ran in to problems last time, you should have used
dbstop if error
and then run your code, and when it stopped running, used size() to examine the size and shape of the inputs and used size() of the expression on the right hand side to figure out what size and shape the left hand side must be.
Hint: re-read the tags you gave to this question. How can you hope to achieve those goals by calculating scalar results?