代码无法协调矢量分配

  • 本文关键字:分配 协调 代码 matlab
  • 更新时间 :
  • 英文 :


我有兴趣修改下面的代码,以找到要在另一个代码中使用的参数I_1I_2I_3I_4。每次我运行代码时,它都会弹出

在赋值A(:(=B中,A和B中的元素数量必须相同

在行"mult(mult==0(=B;"上。

我花了很长时间才弄清楚问题出在哪里。下面是代码:

%%% Some Parameters %%
delta = 0.6; % Blanked subframe ratio
B = [0 0.2 0.4 0.6 0.8 1]; %Power splitting factor
k = 2.3; %Macro BS density
f = k*5;  %Small cell density
j = 300;  %users density  
P_m = 46;   %Macro BS transmission power
P_s = 23;   %SC transmit power
Zm = -15;
Zs = -15;
iter = 30; %Iteration run
h = 500;  %Simulation area
hu = 0.8*h;  %users simulation area
Vm = round(k*h);  %Macro BS average no in h
Vs = round(f*h);  %SC average no in h
Vu = round(j*hu); %%users average no in hu
Pm = 10^(P_m/10)/1000*10^(Zm/10);
Ps = 10^(P_s/10)/1000*10^(Zs/10);
for i = iter;
%% XY coodinates for Macrocell, small cells and users.
Xm = sqrt(h)*(rand(Vm,1)-0.5);      
Ym = sqrt(h)*(rand(Vm,1)-0.5);      
Xs = sqrt(h)*(rand(Vs,1)-0.5);      
Ys = sqrt(h)*(rand(Vs,1)-0.5);      
Xu = sqrt(hu)*(rand(Vu,1)-0.5);   
Yu = sqrt(hu)*(rand(Vu,1)-0.5);
%Total coordinates for MBS and small cells
Total_Coord = [Xs Ys ones(size(Xs)) Xm Ym 2*ones(size(Xm))]; 
%Distance between BSs and users
[Xsm_mat, Xu_mat] = meshgrid(Total_Coord(:,1),Xu);
[Ysm_mat, Yu_mat] = meshgrid(Total_Coord(:,2),Yu);
Distance = sqrt((Xsm_mat-Xu_mat).^2 + (Ysm_mat-Yu_mat).^2);
%% To determine serving BS for each user
[D_m,idx_m] = min(Distance(:,(length(Xs)+1):end),[],2);
idx_m = idx_m + length(Xs);
[D_s,idx_s] = min(Distance(:,1:length(Xs)),[],2);
%% Power received by users from each BS
Psm_mat = [Ps*ones(length(Xu),length(Xs)) 
Pm*ones(length(Xu),length(Xm))]; % Transmit power of MBS and small cells
Pr_n = Psm_mat.*exprnd(1,size(Psm_mat))./(Distance*1e3).^4; 
mult = binornd(1,delta,1,length(Xm)); % Full transmission power of each 
interfering MBS for delta
mult(mult == 0) = B; % Reduced transmission power for (1-delta)
Pr = Pr_n.*[ones(length(Xu),length(Xs)) repmat(mult,length(Xu),1)];% 
Interference from each BS
%% Power received by each user from serving BSs
Prm = Pr(sub2ind(size(Pr),(1:length(idx_m))',idx_m));
Prs = Pr(sub2ind(size(Pr),(1:length(idx_s))',idx_s));
P_m_n = Pr_n(sub2ind(size(Pr_n),(1:length(idx_m))',idx_m));
%% Total interference for each UE
I_T = sum(Pr,2) - Prm - Prs;
I_1 = P_m_n./(Prs + I_T); 
I_2 = Prs./(P_m_n + I_T);
I_3 = B*I_1;
I_4 = Prs./(B*P_m_n + I_T);
end                     

错误出现在"mult(mult==0(=B;"这一行。

我知道这是一个赋值问题,需要左右两个维度相等。如有更正建议,我们将不胜感激。

您的向量mult的长度为Vm(宏BS的数量?(。分配给mult(mult==0)将分配给该向量的子集(那些值等于零的子集(。您所分配的是您的变量B,您将其定义为B = [0 0.2 0.4 0.6 0.8 1],即,它是一个长度为6的向量。除非mult正好有6个零,否则赋值失败。

我非常怀疑这是否是你想要的。看起来您正在尝试分配相同的值("降低的传输功率"(。那么您的B应该是标量。

由于我们不知道你想做什么(而且你的代码也不完全是MCVE(,我们只能猜测。

相关内容

  • 没有找到相关文章

最新更新