If/Else statement within a For loop statement
Ältere Kommentare anzeigen
% 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.
Akzeptierte Antwort
Weitere Antworten (1)
Akash
am 28 Okt. 2014
0 Stimmen
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!