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