Hi guys,
I'm trying to make a plot of directivity for a given radiation intensity pattern (W/sr). However, for some reason my plot for directivity is not showing when I'm using the plot command. This is the code I have.
% Setting up variables theta and phi.
% phi is a given scalar. theta is an array from -pi to pi.
theta = -pi : pi/512 : pi;phi = pi/2;% function Pd
a = sin(2 * pi * sin(theta) * sin(phi)) ./ sin((pi/2) * sin(theta) * sin(phi));pd = (abs(a)).^2;% Calculating Prad to obtain directivity.
x = 0 : pi/1024 : pi;fun = @(x) (abs(sin(2 * pi .* sin(x) * sin(pi/2)) ./ sin((pi/2) .* sin(x) * sin(pi/2)))).^2q0 = integral(fun, 0, pi);Prad = 2 * pi * q0;% Calculating directivity. D = 4 * pi * U / Prad. In this example, U = pd
% (W / sr)
D = 4 * pi .* pd / Prad;figure(1)plot(theta,D)xlabel(theta)ylabel(D)title('Directivity versus theta')
My figure 1 does not show a plot of D versus theta where I am expecting it… can anyone let me know or guide me as to why that is? Is it because my variable D (for directivity) is not an array as I think it is? D shows as a 1×1025 double when I run this code.
Even strangely, I was able to plot pd versus theta using the code below without any issues, in the same .m script file:
figure(1)plot(theta,pd)xlabel('theta')ylabel('pd(theta, phi)')title('pd versus theta')
So I'm confused as to why I can plot pd but not D… I appreciate any help or feedback on this. Thank you for your time!
UPDATE: My plot still does not show correctly when I run my code above (it only shows the title). But, when I right-click my theta and D variables on the workspace, and then use the Plot tab to plot, it does show a plot…
So now I'm even more confused as to why my code doesn't show a plot when I run the script, but I can right-click my variables and get a plot through the plot tab…
Best Answer