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 次查看(过去 30 天)
%% , 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

采纳的回答

Jan
Jan 2021-6-9
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Elementary Math 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by