Matrix assignment inequality problem

조회 수: 1 (최근 30일)
Saint Dee
Saint Dee 2018년 10월 29일
댓글: Bruno Luong 2018년 10월 29일
I am interested in modifying the code below to find the parameters I_1, I_2, I_3 and I_4, to be used in another code. Every time I run the code, it throws up 'In an assignment A(:) = B, the number of elements in A and B must be the same' on this line " mult(mult == 0) = B;". I have spent eternity figuring out what the problem could be. Here is the code...
%%%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
The error appeared on this line "mult(mult == 0) = B;".
I know it to be assignment problem which requires equality in both the left and right dimensions. Suggestions for correction will be appreciated.

답변 (2개)

Bruno Luong
Bruno Luong 2018년 10월 29일
Just shooting in the dark, try replace the problematic instruction with
mult(mult == 0) = B(mult == 0);
  댓글 수: 7
Saint Dee
Saint Dee 2018년 10월 29일
Thanks @Bruno.Yes. For the initial 'Index exceeds matrix dimension' error, I have size(mult) = 1 x 460 and size(B) = 1 x 3, as instructed after changing some parameters and setting B = [0 0.5 1]. Actually, parameters h, hu, Vm, Vs and Vu are for placement of BSs and users within a simulation area as shown in the comment opposite each parameter. B is power reduction factor for the BS of length 3 in the new value. As I said, I'm just trying to find outputs I_1 through I_4, irrespective of individual parameter's dimensions. I will then take it up from there. Thanks
Bruno Luong
Bruno Luong 2018년 10월 29일
Please accept the answer if it helps you. Thanks

댓글을 달려면 로그인하십시오.


madhan ravi
madhan ravi 2018년 10월 29일
Are you sure you have error there ? I faced a problem even before .
Total_Coord = [Xs Ys ones(size(Xs)) Xm Ym 2*ones(size(Xm))];
size(Xs) is 5750 and size(Xm) is 1150 how can you contain them in a matrix?
  댓글 수: 1
Saint Dee
Saint Dee 2018년 10월 29일
@madhan, thanks. What could be done to correct this error? Seems they are building up more!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by