Antenna array pattern in 3D space

Hy guys. Can please someone help me. When I start the program I have an error: Error: Unexpected MATLAB operator.
%Tadej Trinko; three-dimensional antenna array pattern
%email:tadej.trinko@gmail.com
%Jožef Štefan International Postgraduate School (MPS IJS), Ljubljana,
%Slovenia
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);
j = sqrt(-1);
% Magnitude, Phase, X,Y,Z coordinate
for I = 1 : N
Current = I
An(I) = input ('Enter the Magnitude 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 : ') ;
Jp(I) = input ('Enter the Phase of the Current : ') ;
end
Phi=(0:1:360)*pi/180;
Theta=(0:1:180)*pi/180;
[THETA,PHI]=meshgrid(Theta,Phi);
% calculate the array factor
for I=1:N
R=An(I)*exp(1j.*(Ep+Jp(I)));
Ep=B*((Xn(I).*cos(PHI).*sin(THETA))+(Yn(I).*sin(THETA).*sin(PHI))+(Zn(I).*cos(THETA)));
end
%plot the array factor
X=R.*sin(THETA).*cos(PHI);
Y=R.*sin(THETA).*sin(PHI);
Z=R.*cos(THETA);
figure();
mesh(X,Y,Z); %display
surf(X,Y,Z) %colored faces
Thank you for any advice or comment.
Regards, Tadej

 Accepted Answer

Hi Tadej, In this for loop
for I=1:N
R=An(I)*exp(1j.*(Ep+Jp(I)));
Ep=B*((Xn(I).*cos(PHI).*sin(THETA))+(Yn(I).*sin(THETA).*sin(PHI))+(Zn(I).*cos(THETA)));
end
You attempt to access the value of Ep the first time through the loop before it has been assigned a value. Perhaps you just need to swap the two lines and place the Ep= assignment before the R=
Also, do you know about the new Phased Array System Toolbox? That toolbox will greatly enhance your ability to design antennas and model phased array systems.
Wayne

4 Comments

Thank you Wayne for your comment. I will add Phased Array System Toolbox. Thank you. Have nice day.
I have MatLab version R2009b. So I will have to download version R2011a, or is there any upgrade for this Toolbox?
Phased Array System Toolbox is released in R2011a so you will need R2011a to use it. HTH.
Downloading. Thank you Chen.

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 30 Aug 2011
Which line does it complain about, and which column?:
I am not sure that 1j can be used to mean 1 times the imaginary unit. I know 1i can be used. As you defined j as sqrt(-1) it would seem to be more consistent for you to use 1*j in that location.
Your second "for" loop, the one with the comment "calculate the array factor", does not store its results, and does not use the results in further computation. That is going to cause R and Ep to be overwritten during each iteration of the loop, and so will contain only a single value at the end of the loop.
I would suggest that you want R(I)= ... and Ep(I) = ... but the Ep expression appears to have a vector result, so at the very least it would have to be Ep(I,:) or Ep(:,I). I also see that If you were to use R(I) then R would end up of length N, but R is then .* by trig array values that are 361 x 181 so multiplying by a vector R of length N is problematic.
Your code appears to be incomplete and incorrect.

9 Comments

Ah, I just noticed your second "for" loop does use Ep in defining R. But it does that before Ep has been defined at all.
It just said:
??? 3Darray_2
|
Error: Unexpected MATLAB operator.
Thank you Walter for your comment. I will chech my code more detailed. Have a nice day.
Is there any matlab debugger?
Did you try to store this in a file named 3Darray_2.m ? Filenames for scripts have to follow the same rules as filenames for functions, which in turn have to follow the same rules as the names of identifiers: the first character must be an upper or lower case English ('Latin') letter, and the characters after that can be upper or lower case English letters or the English digits 0 through 9 or the character underscore ('_')
Walter, you were right. The filname was wrong. Thank you :)
But now I have priblem with equation of Ep(I).
Error note: ??? In an assignment A(I) = B, the number of elements in B and I must be the same.
Error in ==> Array3Dex2 at 30 Ep(I)=((Xn(I).*cos(PHI).*sin(THETA))+(Yn(I).*sin(THETA).*sin(PHI))+(Zn(I).*cos(THETA)));
My code:
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
Phi=(0:1:360)*pi/180; Theta=(0:1:180)*pi/180; [THETA,PHI]=meshgrid(Theta,Phi);
% 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+(Jp(I)*pi/180))); end
%plot the array factor X=R.*sin(THETA).*cos(PHI); Y=R.*sin(THETA).*sin(PHI); Z=R.*cos(THETA);
figure(); mesh(X,Y,Z); %display surf(X,Y,Z) %colored faces
Can you please help me? Or, if you can write a literature where I can study in correct solution.
Please re-read the "I would suggest that you want" section of my response...
You are correct Walter. Everytime I get error:
??? Subscripted assignment dimension mismatch.
Error in ==> Array3Dex6 at 31
Ep(:,I)= B.*((Xn(I).*cos(PHI).*sin(THETA))+(Yn(I).*sin(THETA).*sin(PHI))+(Zn(I).*cos(THETA)));
Is there any different way to avoid error?

Sign in to comment.

Asked:

on 30 Aug 2011

Community Treasure Hunt

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

Start Hunting!