arithmetic operations with arrays of unequal size in matlab
1 view (last 30 days)
Show older comments
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
0 Comments
Answers (1)
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
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.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!