How to plot multiple function results depending on changed variable?

4 次查看(过去 30 天)
I am wondering how to plot multiple function results depending on changed variable freq?
Starting inputs are r=1 and freq=5 000 000 000, and i want to show on one figure results from freq = 5*10^9 up to 9*10^9.
Does anyone have any ideas?
Thanks!
function [rcsdb] = rcs_circ_plate (r, freq)
eps = 0.000001;
lambda = 3.e+8 / freq;
index = 0;
for aspect_deg = 0.:.1:180
index = index +1;
aspect = (pi /180.) * aspect_deg;
if (aspect == 0 | aspect == pi)
rcs_po(index) = (4.0 * pi^3 * r^4 / lambda^2) + eps;
rcs_mu(index) = rcs_po(1);
else
val1m = lambda * r;
val2m = 8. * pi * sin(aspect) * (tan(aspect)^2);
rcs_mu(index) = val1m / val2m + eps;
end
end
rcsdb = 10. * log10(rcs_po);
rcsdb_mu = 10 * log10(rcs_mu);
angle = 0:.1:180;
plot(angle,rcsdb_mu)
grid;
xlabel ('\theta (deg)');
ylabel ('RCS (dB/m^2)');
axis tight
legend('f = 4 Ghz')
freqGH = num2str(freq*1.e-9);
end
  1 个评论
dpb
dpb 2021-6-9
Probably easiest is to move the plotting outside the function, return the data to be plotted from the function and call the function in a loop over the desired range of frequencies, plotting each result in turn in the loop.
See hold on and examples to put more than one set of data on a given axes.

请先登录,再进行评论。

采纳的回答

Sulaymon Eshkabilov
This is one of the easy ways how you can calculate and plot the results.
r = 1;
freq = 5e9:9e9;
for ii=1:numel(freq)
OUT(ii) = rcs_circ_plate (r, freq(ii));
end
plot(OUT) % Take what to be along the x axis
grid on
%
function [rcsdb] = rcs_circ_plate (r, freq)
eps = 0.000001;
lambda = (3.e+8)./ freq;
index = 0;
for aspect_deg = 0.:.1:180
index = index +1;
aspect = (pi /180.) * aspect_deg;
if (aspect == 0 | aspect == pi)
rcs_po(index) = (4.0 * pi^3 * r^4 / lambda^2) + eps;
rcs_mu(index) = rcs_po(1);
else
val1m = lambda * r;
val2m = 8. * pi * sin(aspect) * (tan(aspect)^2);
rcs_mu(index) = val1m / val2m + eps;
end
end
rcsdb = 10. * log10(rcs_po);
rcsdb_mu = 10 * log10(rcs_mu);
angle = 0:.1:180;
plot(angle,rcsdb_mu)
grid;
xlabel ('\theta (deg)');
ylabel ('RCS (dB/m^2)');
axis tight
legend('f = 4 Ghz')
freqGH = num2str(freq*1.e-9);
end

更多回答(0 个)

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by