I have P=[2 3 4 0 5 1 0 2 ]; and I want to create a loop to remove zeros from P and calculate C, description in the code

1 view (last 30 days)
%% , for example P=[2 0 4 0 5 1 2 0 ]; and after the first iteration P=[2 4 0 5 1 2 0]; and second iteration P=[2 0 4 5 1 2 0 ]; and third one
P=[2 0 4 0 5 1 2 ]; which one will give me the best C .. if I removed the first zero, the second or the thrid one.
%%parameters
clc;
clear;
Pt=5;
Pn=2;
W=rand(4,8);
HT=rand(8,4);
D_Matrix = HT*W_bar;
D_Square = (abs(diag(D_Matrix))').^2;
P = waterfill(Pt,Pn./D_Square);
Find_Zero=find(~P); %Find Zero
if (~isempty(Find_Zero))
while (~isempty(Find_Zero))
First_Z=Find_Zero(1); %First Zero
W_bar(:,First_Z) = []; %Delete Col
HT(First_Z,:) = []; %Delete Row
D_Matrix = HT*W_bar;
D = (abs(diag(D_Matrix))').^2;
P = waterfill(Pt,Pn./D);
Find_Zero=find(~P); %Find Zero Power
end
R = P.*D/Pn;
C = sum(log2(1+R)); %Capacity
end

Accepted Answer

Jan
Jan on 9 Jun 2021
P = [2 0 4 0 5 1 2 0 ];
zeroIndex = find(P == 0);
for k = 1:numel(zeroIndex)
Q = P;
Q(zeroIndex(k)) = [];
... Insert your tests of Q here
end

More Answers (0)

Categories

Find more on Elementary Math in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!