Borrar filtros
Borrar filtros

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

1 visualización (últimos 30 días)
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
  2 comentarios
Walter Roberson
Walter Roberson el 12 de Sept. de 2011
See also this earlier question on the same topic:
http://www.mathworks.com/matlabcentral/answers/14772-antenna-array-pattern-in-3d-space
Tadej
Tadej el 12 de Sept. de 2011
I tried to change Ep(I) with Ep(:,I) or Ep(I,:), but the error was still there.

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 12 de Sept. de 2011
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?
  6 comentarios
Tadej
Tadej el 13 de Sept. de 2011
Thank you Walter. You are very helpful to me.
I have another question. I noticed that all 3D plots are made by using meshgrid function before AF function in my case. In my case I am able to get rid off 2xfor loops. But now I have a problem with calculating C(I). But if we look code above, this problem was not present. Do you maybe know what is the case?
code:
clear all;
dbstop if error
% 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 Element : ') ;
Jp(I) = input ('Enter the Phase of the Current Element : ') ;
Xn(I) = input ('Enter the Position of Current Element on X-axis : ') ;
Yn(I) = input ('Enter the Position of Current Element on Y-axis : ') ;
Zn(I) = input ('Enter the Position of Current Element on Z-axis : ') ;
end
%azimut--> 0<Phi<360, elevation--> 0<Theta<180
Phi = (1:1:360)*pi/180;
Theta = (1:1:180)*pi/180;
[THETA,PHI] = meshgrid(Theta,Phi);
% calculate the array factor
for I = 1:N
C(I) = Xn(I).*sin(THETA).*cos(PHI);
D(I) = Yn(I).*sin(THETA).*sin(PHI);
E(I) = Zn(I).*cos(THETA);
Ep(I) = B.*(C(I)+D(I)+E(I));
R(I)= An(I).*exp(1i.*(Ep(I) +(Jp(I).*pi/180)));
end
h(PHI, THETA) = abs(sum(R));
AF(PHI, THETA) = abs(h(PHI, THETA));
%plot the array factor
X = AF.*sin(THETA).*cos(PHI);
Y = AF.*sin(THETA).*sin(PHI);
Z = AF.*cos(THETA);
figure(1);
mesh(X,Y,Z); %display
surf(X,Y,Z) %colored faces
Thank you in advance.
Greetings, Tadej
Tadej
Tadej el 13 de Sept. de 2011
C(I):
meshgrid() function befor AF() function
C(I) = Xn(I).*sin(THETA).*cos(PHI);
Xn(I)--> 1x2 double
PHI--> 360x180 double
THETA--> 360x180 double
meshgrid() function after AF() lunction
C(I) = Xn(I).*sin(deg2rad(THETA)).*cos(deg2rad(PHI));
Xn(I)--> 1x2 double
PHI--> 180x360 double
THETA--> 180x360 double

Iniciar sesión para comentar.

Más respuestas (1)

Tadej
Tadej el 19 de Sept. de 2011
Walter, could you please help me and tell me what is wrong with my code?
%Tadej Trinko; three-dimensional antenna array pattern
%email:tadej.trinko@gmail.com
%Jožef Štefan International Postgraduate School (MPS IJS), Ljubljana,
%Slovenia
clear all;
close all
dbstop if error
V1=0; A1=0; C=0;
V2=0; A2=0; D=0;
V3=0; A3=0; E=0;
Ep=0; AnI=0; JpI=0;
R=0;
% element numbers N, wavenumber B
N = 3; %Number of elemnts in array
B = 0.14; %B =(2*pi/lambda), wavenumber
% Magnitude, Phase, X,Y,Z coordinate
An = [2 2 2]; %Magnitude of 1st, 2nd and 3rd element
Jp = [120 90 60]; %Phase of 1st, 2nd and 3rd element
Xn = [1 2 3]; % Position of 1st, 2nd and 3rd element on X-axis
Yn = [1 2 3]; % Position of 1st, 2nd and 3rd element on Y-axis
Zn = [1 2 3]; % Position of 1st, 2nd and 3rd element on Z-axis
%azimut--> 0<Phi<360, elevation--> 0<Theta<180
Phi = (1:1:360)*pi/180; %azimuth
Theta = (1:1:180)*pi/180; %elevation
[THETA,PHI] = meshgrid(Theta,Phi);
% calculate the array factor
%size(THETA)
%length(THETA)
%convert vector into matrix C = Xn .* sin(THETA) .* cos(PHI);
V1 = repmat(Xn,360,60);
A1 = sin(THETA) .* cos(PHI);
C = A1.*V1;
%convert vector into matrix D = Yn * sin(THETA) * sin(PHI);
V2 = repmat(Yn,360,60);
A2 = sin(THETA) .* sin(PHI);
D = A2.*V2;
%convert vector into matrix E = Zn * cos(THETA);
V3 = repmat(Zn,360,60);
A3 = cos(THETA);
E = A3.*V3;
Ep = B.*(C+D+E);
%convert degree to radian
Jp = (Jp.*pi)/180;
%convert vector An, Jp into martix
AnI = repmat(An,360,60);
JpI = repmat(Jp,360,60);
R = AnI.*exp(1i.*(Ep + JpI)); %Equation for array factor
%h(PHI, THETA) = R;
%AF(PHI, THETA) = abs(h(PHI, THETA));
%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
Best regards, Tadej

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by