How to plot multiple function results depending on changed variable?

조회 수: 2 (최근 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
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 CenterFile Exchange에서 Simulink에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by