If/Else statement within a For loop statement
Show older comments
% OBJ: Clear command window and workspace
clear
clc
% OBJ: Create the vector of angles theta
theta=[-pi/2: pi/100: pi/2];
% OBJ: Calculate gain for each angle theta
for G=[theta];
if theta==0
G=0.5;
else
G=abs((sin(4.*theta))./(4.*theta));
end
end
% OBJ: Create and display a polar plot of G vs. theta
polar(theta,G)
title('Antenna Gain vs. Theta')
The reason I have to do this is to account for the point where theta will equal 0 and leave that data point undefined but idk why the data point remains undefined. When I run the script, everything is correct and the graph looks good, except for that one data point which remains undefined.
There's something wrong syntactically in the loop, but I cannot ascertain what it is. Any help is appreciated.
Accepted Answer
More Answers (1)
Akash
on 28 Oct 2014
0 votes
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!