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 Center および File ExchangeElementary Math についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by