The Loops in the first picture are required, the description is below
    4 次查看(过去 30 天)
  
       显示 更早的评论
    
%% Suppose I have W and Theta, k=1:K .. K=(any value) let say 10 
%% 
                Alfa_k=zeros(1,k);
                Alfa_i=zeros(1,k);
                Angle_h_w=zeros(1,k);
                Angle_g_h_w=zeros(1,k);
                n0=zeros(1,k);
               for t_1=1:k
                   Alfa_k(t_1) = 1/(abs(H(t_1,:)*W(:,t_1)));
                    Angle_h_w(t_1) = angle(H(t_1,:)*W(:,t_1));
                   Alfa_i(t_1) = 0;
                 for t_2=1:k
                     Alfa_i(t_1) = Alfa_i(t_1) + 1/(abs(H(t_2,:)*W(:,t_2)));
                 end
                     Alfa_i(t_1) = Alfa_i(t_1) - Alfa_k(t_1);  % Sum of Alfa_i
               end
               L_k = n*(Alfa_k./Alfa_i); % Number of IRS Elements Assigned to UE ..
                               % Total IRS Elements * Proportion of IRS Elements
               r = n-(sum(L_k)); %The Remaining IRS Elements ..
                                 % Are Assigned to The Weakest UE
               [argvalue, argmax] = max(Alfa_k);
               L_k0=L_k(argmax);
               L_k0 = L_k0+r;
               [Alfa_m,idx]= sort(Alfa_k, 'descend'); % sort UE
               L_m = sort(L_k, 'descend');
               F = F(idx,:);  % sort the whole matrix using the sort idx
               W = W(:,idx);  % sort the whole matrix using the sort idx
               for t_3=1:k
                   n0(t_3)=(abs(F(t_3,:)*G*W(:,t_3)))
                   Angle_g_h_w(t_3) = angle(F(t_3,:)*G*W(:,t_3))
               end
               [argval, arg_max] = max(n0)
               Theta_k = -Angle_h_w-Angle_g_h_w
3 个评论
  Image Analyst
      
      
 2021-12-15
				
      编辑:Image Analyst
      
      
 2021-12-15
  
			Original question attached
%% Suppose I have W and Theta, k=1:K .. K=(any value) let say 10 
%% 
                Alfa_k=zeros(1,k);
                Alfa_i=zeros(1,k);
                Angle_h_w=zeros(1,k);
                Angle_g_h_w=zeros(1,k);
                n0=zeros(1,k);
               for t_1=1:k
                   Alfa_k(t_1) = 1/(abs(H(t_1,:)*W(:,t_1)));
                    Angle_h_w(t_1) = angle(H(t_1,:)*W(:,t_1));
                   Alfa_i(t_1) = 0;
                 for t_2=1:k
                     Alfa_i(t_1) = Alfa_i(t_1) + 1/(abs(H(t_2,:)*W(:,t_2)));
                 end
                     Alfa_i(t_1) = Alfa_i(t_1) - Alfa_k(t_1);  % Sum of Alfa_i
               end
               L_k = n*(Alfa_k./Alfa_i); % Number of IRS Elements Assigned to UE ..
                               % Total IRS Elements * Proportion of IRS Elements
               r = n-(sum(L_k)); %The Remaining IRS Elements ..
                                 % Are Assigned to The Weakest UE
               [argvalue, argmax] = max(Alfa_k);
               L_k0=L_k(argmax);
               L_k0 = L_k0+r;
               [Alfa_m,idx]= sort(Alfa_k, 'descend'); % sort UE
               L_m = sort(L_k, 'descend');
               F = F(idx,:);  % sort the whole matrix using the sort idx
               W = W(:,idx);  % sort the whole matrix using the sort idx
               for t_3=1:k
                   n0(t_3)=(abs(F(t_3,:)*G*W(:,t_3)))
                   Angle_g_h_w(t_3) = angle(F(t_3,:)*G*W(:,t_3))
               end
               [argval, arg_max] = max(n0)
               Theta_k = -Angle_h_w-Angle_g_h_w
回答(1 个)
  Walter Roberson
      
      
 2021-6-29
        Example with your second set of code. The array sizes are constructed to be consistent with your code
k = 5;
m = 3;
M = 7;
H = randi(9, k, M)
W = randi(9, M, k)
n = rand()
F = randi(9, k, m)
G = randi(9, m, M)
                Alfa_k=zeros(1,k);
                Alfa_i=zeros(1,k);
                Angle_h_w=zeros(1,k);
                Angle_g_h_w=zeros(1,k);
                n0=zeros(1,k);
               for t_1=1:k
                   Alfa_k(t_1) = 1/(abs(H(t_1,:)*W(:,t_1)));
                    Angle_h_w(t_1) = angle(H(t_1,:)*W(:,t_1));
                   Alfa_i(t_1) = 0;
                 for t_2=1:k
                     Alfa_i(t_1) = Alfa_i(t_1) + 1/(abs(H(t_2,:)*W(:,t_2)));
                 end
                     Alfa_i(t_1) = Alfa_i(t_1) - Alfa_k(t_1);  % Sum of Alfa_i
               end
               L_k = n*(Alfa_k./Alfa_i); % Number of IRS Elements Assigned to UE ..
                               % Total IRS Elements * Proportion of IRS Elements
               r = n-(sum(L_k)); %The Remaining IRS Elements ..
                                 % Are Assigned to The Weakest UE
               [argvalue, argmax] = max(Alfa_k);
               L_k0=L_k(argmax);
               L_k0 = L_k0+r;
               [Alfa_m,idx]= sort(Alfa_k, 'descend'); % sort UE
               L_m = sort(L_k, 'descend');
               F = F(idx,:);  % sort the whole matrix using the sort idx
               W = W(:,idx);  % sort the whole matrix using the sort idx
               for t_3=1:k
                   n0(t_3)=(abs(F(t_3,:)*G*W(:,t_3)))
                   Angle_g_h_w(t_3) = angle(F(t_3,:)*G*W(:,t_3))
               end
               [argval, arg_max] = max(n0)
               Theta_k = -Angle_h_w-Angle_g_h_w
4 个评论
  Walter Roberson
      
      
 2021-6-29
				No, I do not know how to make it compatible with the first picture. If I were coding it, I would start over without your existing code.
另请参阅
类别
				在 Help Center 和 File Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



