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 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Matthew Worker
am 9 Jun. 2021
Kommentiert: Rena Berman
am 16 Dez. 2021
%% , 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
1 Kommentar
Akzeptierte Antwort
Jan
am 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
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Elementary Math finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!