Average of a function handle

21 Ansichten (letzte 30 Tage)
Ca Mai
Ca Mai am 15 Nov. 2020
Kommentiert: Ca Mai am 15 Nov. 2020
can someone please help me with ploting the mean of the function below?
d0=1;% Free space reference distance in meters
c = 3e8; %% speed of light (m/s)
n = 2; % Path loss exponent (PLE)
SF = 4.0;% Shadow fading standard deviation in dB
f=3; %frequency
h_BS=35; % base station high
TXPower = 30;% Tx power
PL_dB =@(TRDistance)( 20*log(4*pi*d0*f*1e9/c) + 23.1*(1-0.03*((h_BS-35)/35))*log((TRDistance)) + SF*randn);
for TRDistance = linspace(1,500,30)%1 to 28 in 30 steps
% Calculate the received power
if PL_dB(TRDistance) < 0
Pr_dB = @(TRDistance) TXPower + PL_dB(TRDistance);
else
Pr_dB = @(TRDistance) TXPower - PL_dB(TRDistance);
end
end
fplot(Pr_dB, [1,500]);

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 15 Nov. 2020
d0=1;% Free space reference distance in meters
c = 3e8; %% speed of light (m/s)
n = 2; % Path loss exponent (PLE)
SF = 4.0;% Shadow fading standard deviation in dB
f=3; %frequency
h_BS=35; % base station high
TXPower = 30;% Tx power
PL_dB =@(TRDistance)( 20*log(4*pi*d0*f*1e9/c) + 23.1*(1-0.03*((h_BS-35)/35))*log((TRDistance)) + SF*randn);
TrDistances = linspace(1,500,30);
Pr_Db = zeros(size(TrDistances));
for didx = 1 : numel(TrDistances)
TrDistance = TrDistances(didx);
% Calculate the received power
pldb = PL_dB(TRdistance);
if pldb < 0
Pr_dB(didx) = TXPower + pldb;
else
Pr_dB(didx) = TXPower - pldb;
end
end
plot(TrDistances, Pr_dBmean);
Note: instead of the if you can use:
PR_db(didx) = TXPower - abs(PL_dB(TRdistance));
  4 Kommentare
Walter Roberson
Walter Roberson am 15 Nov. 2020
Bearbeitet: Walter Roberson am 15 Nov. 2020
d0=1;% Free space reference distance in meters
c = 3e8; %% speed of light (m/s)
n = 2; % Path loss exponent (PLE)
SF = 4.0;% Shadow fading standard deviation in dB
f=3; %frequency
h_BS=35; % base station high
TXPower = 30;% Tx power
PL_dB =@(TRDistance)( 20*log(4*pi*d0*f*1e9/c) + 23.1*(1-0.03*((h_BS-35)/35))*log((TRDistance)) + SF*randn);
TrDistances = linspace(1,500,30);
Pr_dB = zeros(size(TrDistances));
for didx = 1 : numel(TrDistances)
TrDistance = TrDistances(didx);
% Calculate the received power
Pr_dB(didx) = TXPower - abs(PL_dB(TrDistance)); %Notice no @ anywhere here
end
plot(TrDistances, Pr_dB);
Ca Mai
Ca Mai am 15 Nov. 2020
thank you very much

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB Support Packages finden Sie in Help Center und File Exchange

Produkte


Version

R2013a

Community Treasure Hunt

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

Start Hunting!

Translated by