Anonymous Function soustraction problem with a parameter

조회 수: 11 (최근 30일)
Ca Mai
Ca Mai 2020년 10월 23일
댓글: Ca Mai 2020년 10월 26일
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
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.
Ca Mai
Ca Mai 2020년 10월 23일
ok. ı have already done that. I removed all the dependencies.

댓글을 달려면 로그인하십시오.

채택된 답변

Rik
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
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.
Ca Mai
Ca Mai 2020년 10월 26일
ok. thanks a lot

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2013a

Community Treasure Hunt

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

Start Hunting!

Translated by