How to plot multiple function results depending on changed variable?

1 回表示 (過去 30 日間)
Petar Markic
Petar Markic 2021 年 6 月 9 日
回答済み: Sulaymon Eshkabilov 2021 年 6 月 9 日
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
Sulaymon Eshkabilov 2021 年 6 月 9 日
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 Center および File ExchangeSimulink についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by