Anonymous Function soustraction problem with a parameter
11 次查看(过去 30 天)
显示 更早的评论
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;
clc;
%--------------------------------------------------------------------------
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
TXPower=30;
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
figure;
fplot(Pr_dB, [1,28]);
xlabel('f');
ylabel('Pr_dB');
2 个评论
Rik
2020-10-23
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.
采纳的回答
Rik
2020-10-23
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));
end
fprintf('the TX is %d .\n',(TXPower));
3 个评论
Rik
2020-10-23
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!