My plot for directivity is not showing?

3 次查看(过去 30 天)
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)))).^2
q0 = 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 1x1025 double when I run this code.Directivity Plot Issue.jpg
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...theta versus D.jpg
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...

采纳的回答

Yasasvi Harish Kumar
编辑:Yasasvi Harish Kumar 2019-2-26
Hi,
Your xlabel and ylabel need to be in quotes which is missing in your script.
% 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)))).^2
q0 = 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')
This fixes your problem.
Regards
  1 个评论
Andrew Yip
Andrew Yip 2019-2-27
Yasasvi, indeed it does fix the problem! I missed the quotes, and adding them fixed the problem. Thank you!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by