arithmetic operations with arrays of unequal size in matlab

93 views Asked by At

I am attempting to calculate a 2D polar plot of the power pattern of an Archimedean spiral array of isotropic antennas in MATLAB. This requires a theta and phi array that are both different sizes.

The code I am using is as follows:

clear all
close all
clc
r=27000;  
phi=0:.02:2*pi;
theta=0:.02:pi/2;
px=r.*cos(phi);
py=r.*sin(phi);
wL=1;
k=(2*pi)/wL;
d=px.*sin(theta).*cos(phi)+py.*sin(theta).*sin(phi);
phase=0;
psi=k.*d+phase;

N=27;
PowPatt=(sin(N.*(psi./2))./(N.*sin(psi./2))).^2;
polar(psi,PowPatt)

Naturally I get the following error:

??? Error using ==> times
Matrix dimensions must agree.

Error in ==> powerpattern at 11
d=px.*sin(theta).*cos(phi)+py.*sin(theta).*sin(phi);

Is there anyway to change my code to perform the arithmetic operations on the theta and phi arrays? Thank you.

Patrick

1

There are 1 answers

0
chipaudette On

The code itself doesn't work because theta and phi are different sizes. They need to be the same size to do the element-wise multiply ".*" operation. Or, they need to be compatible sizes to do a matrix-wise multiply "*". You don't have either, so your problem is not with the code but with your interpretation of the antenna array equations. We can't help you there.

I'm guessing that the array equations intend for you to either permute across all combinations of phi and theta so that you can then sum over one or more dimensions of phi and theta. Therefore, you're likely going to have to introduce a for loop and/or a sum() operation. Since I don't know your antenna array equations, I can't help. You'll have to go back and look at the physics. Once you understand the array antenna equations better, you'll be able to code them better.