Matrix assignment inequality problem

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.

Answers (2)

Just shooting in the dark, try replace the problematic instruction with
mult(mult == 0) = B(mult == 0);

7 Comments

Thanks Bruno. On replacing with the suggestion, it threw in "Index exceeds matrix dimension" on the same line.
Type in command line
>> dbstop if error
Run the code, when error occurs, get the size of mult
>> size(mult)
>> size(B)
Then report the results
When I pressed run, it opened a 'meshgrid.m' window and the following error..
Error using repmat Out of memory. Type HELP MEMORY for your options.
Error in meshgrid (line 59)
yy = repmat(ycol,size(xrow));
Error in Untitled5 (line 38)
[Xsm_mat, Xu_mat] = meshgrid(Total_Coord(:,1),Xu);
Further running size(mult) and size(B), the following error popped up for both..
Undefined function or variable 'mult'.
Undefined function or variable 'B'.
59 yy = repmat(ycol,size(xrow));
I have never encountered this error since I've been running the code. My recurrent error had been on the 'mult' line until @madhan identified another error in the dimensions of Xs and Xm. I'm totally derailed.
Then it becomes too messy for me to guide you, sorry.
Actually I reeread the code and this statement
mult(mult == 0) = B
doesn't look at all right. mult is a Poisson RV (like # of photons) of length Vm = round(k*h) number of detectors? and B is array of powers (splited by BS?) of length 6.
Not sure why this statement is used to connect two things that are not related, even by the length.
I think this code is very buggy.
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
Please accept the answer if it helps you. Thanks

Sign in to comment.

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 Comment

@madhan, thanks. What could be done to correct this error? Seems they are building up more!

Sign in to comment.

Asked:

on 29 Oct 2018

Commented:

on 29 Oct 2018

Community Treasure Hunt

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

Start Hunting!