MATLAB Answers

Anonymous Function soustraction problem with a parameter

1 view (last 30 days)
Ca Mai
Ca Mai on 23 Oct 2020
Commented: Ca Mai on 26 Oct 2020
Hello. ı want to plot a correlation between the received power (Pr(dB)) and the frequency (f)(variable of an anonymous function PL_dB). my equation is Pr_dB = @(f) TXPower - PL_dB(f);
where Pr_dB is the received power,
TXPower the transmitted power. TXPower is a parameter that can be enter from the GUI,
PL_dB the path loss. it is function of the frequency f.
the problem with the code is that the Pr(dB) gives me wrongs answers.
Pr_dB =30 -102= -72 but the code gives me 41 as Pr_dB value. Can someone please help me with that? here below is the code.
close all;
clear variables;
SF=4.0;% Shadow fading standard deviation in dB
d0=1;% Free space reference distance in meters
c = 3e8; %% speed of light (m/s)
h_BS = 15; % Base station height in meters (10-150 m), only used for the RMa scenario
TRDistance= 100;
lambda = @(f) (c/(f*1e9));
%Path Loss
PL_dB =@(f)( 20*log(4*pi*d0*f*1e9/c) + 30.7*(1-0.049*((h_BS-35)/35))*log((TRDistance)) + SF*randn);
%Received power
Pr_dB =@(f) TXPower - PL_dB(f);
%verify (PL_dBm), (Pr_dBm)and (TXPower) values
fprintf('the path loss is %d , the received power is %d .\n ',func2str(PL_dB) ,func2str(Pr_dB));
fprintf('the TX is %d .\n',(TXPower));
%ploting the the recived power depending on the frequency
fplot(Pr_dB, [1,28]);


Rik on 23 Oct 2020
Without your input variables it is impossible to run your code. So right now we can't confirm your desired output is correct, nor that there is an actual problem with your code. Try to make a MWE so we can run your code without any other dependencies and can reproduce your issue.
Ca Mai
Ca Mai on 23 Oct 2020
ok. ı have already done that. I removed all the dependencies.

Sign in to comment.

Accepted Answer

Rik on 23 Oct 2020
You were not actually evaluating the function for values of f; you were entering the anonymous function as a char array.
%verify (PL_dBm), (Pr_dBm)and (TXPower) values
for f=linspace(1,28,30)%1 to 28 in 30 steps
fprintf('the path loss is %.0f , the received power is %.0f .\n ',PL_dB(f) ,Pr_dB(f));
fprintf('the TX is %d .\n',(TXPower));


Rik on 23 Oct 2020
You're welcome. If this solved your question, feel free to mark my answer as accepted answer. If not, feel free to comment with your remaining issues.

Sign in to comment.

More Answers (0)




Community Treasure Hunt

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

Start Hunting!

Translated by