arithmetic operations with arrays of unequal size in matlab

1 view (last 30 days)
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

Answers (1)

Matt J
Matt J on 22 Nov 2014
Edited: Matt J on 22 Nov 2014
What should be happening at the line that is generating the error message? Are you trying to compute d for all combinations of phi(i) and theta(j) ? If so, generate phi and theta using ndgrid
[phi,theta]=ndgrid(0:.02:2*pi, 0:.02:pi/2);
  2 Comments
Patrick
Patrick on 22 Nov 2014
Edited: Matt J on 23 Nov 2014
Hi Matt. The code definitely executes now. Thank you for the fast the response. However, the plot is no longer normalized, i.e. does not have a maximum value of 1. Actually, nothing appears on the plot figure when I execute the code. My new code is below. What might be causing this?
clear all
close all
clc
r=27000;
[phi,theta]=ndgrid(0:.02:2*pi, 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)
Matt J
Matt J on 23 Nov 2014
However, the plot is no longer normalized, i.e. does not have a maximum value of 1.
What do you mean "no longer"? The error prevented you from ever having a plot.
Anyway, what exactly is supposed to have a maximum value of 1? PowPatt? I see nothing in the code to indicate that it should.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!