I've tried running this code but unfortunately it doesn't work because of the 'symPower' is unrecognizable function or variable. Would definitely appreciate the help. Thanks

조회 수: 2 (최근 30일)
function [powerFactor,decOrder] = allocatePower(symPower,gainH,targetSNR_1,targetSNR_2,nVar)
% This function is to allocate transmit power to users based on their
% channel gain. The power is allocated to make both users achieve a target
% SNR.
[numUE,numSC] = size(gainH);
% Channel gain levels
gainDiff = diff(gainH,[],1); % column2-column1
highGain(logical(gainDiff<0)) = 1;
highGain(logical(gainDiff>0)) = 2;
lowGain(logical(gainDiff>0)) = 1;
lowGain(logical(gainDiff<0)) = 2;
highGain = highGain.';
lowGain = lowGain.';
% Calculate power allocation factor
powerFactor = zeros(numSC,numUE);
for sc = 1:numSC
lowPower = targetSNR_2*nVar./(symPower*gainH(highGain(sc),sc));
highPower = (targetSNR_1*(lowPower.*symPower*gainH(highGain(sc),sc)+nVar))./symPower*gainH(lowGain(sc),sc);
highPowerFactor = highPower./(highPower+lowPower);
lowPowerFactor = lowPower./(highPower+lowPower);
powerFactor(sc,highGain(sc)) = lowPowerFactor;
powerFactor(sc,lowGain(sc)) = highPowerFactor;
end
decOrder = zeros(numSC,numUE);
[~,decOrder(:,1)] = max(powerFactor,[],2);
[~,decOrder(:,2)] = min(powerFactor,[],2);
Output: allocatePower(symPower, gainH, targetSNR_1, targetSNR_2, nVar)
Unrecognized function or variable 'symPower'.

답변 (1개)

Vijay
Vijay 2022년 10월 14일
Hello @Kaeshwin
Please make sure all variables are defined before using them.
For example
symPower, on of the variables used while calling, must be defined first
you need to define all the variables before calling the function allocatePower.
Example Values:
symPower = 1;
gainH = 0.2;
targetSNR_1 = 10;
targetSNR_2 = 20;
nvar=100;
%above values are just for example, please chose suitable values.
[output_1, output_2] = allocatePower(symPower, gainH, taragetSNR_1, targetSNR_2, nvar);

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by