Info

This question is closed. Reopen it to edit or answer.

could anyone help me to fix the following issue

2 views (last 30 days)
Prabha Kumaresan
Prabha Kumaresan on 7 Jan 2018
Closed: Stephen23 on 7 Jan 2018
A =[1 2 3 4 5 31;
6 7 8 9 10 32;
11 12 13 14 15 33;
21 22 23 24 25 34;
26 27 28 29 30 35]
B =[
0 0 41 0 0 0;
45 0 0 0 0 0;
0 43 0 0 0 49;
0 0 0 42 0 0;
0 0 0 0 44 0]
% A=rand(50,100)
% B=diag(randi([1 10],50,1))
N_G=2 %No of group
R = cell(N_G,1)
sumR = cell(N_G,1)
for d=1:1:N_G
%------------------------------------------
% select No of UE randomly
%------------------------------------------
if d==N_G
sz=length(B(:,1))
e=sz
else
if d==1
e=randi([2 3])% select No of UE randomly
else
sz=length(B(:,1))
sz=ceil(sz/2)
e=randi([1 sz])% select No of UE randomly
end
end
%------------------------------------------
idx=randsample(1:size(B,1),e)
%------------------------------------------
% Getting arry A and B from random index
%------------------------------------------
for i=1:length(idx)
X(i,:) = B(idx(i),:)
Y(i,:) = A(idx(i),:)
Xi(i)=find(X(i,:))
end
X=[X(1:i,:)]
Y=[Y(1:i,:)]
%------------------------------------------
% Replacing
%------------------------------------------
non_0=sum(X)
non_0=repmat(non_0,i,1)
S=X
S(non_0 & X==0)=Y(non_0 & X==0)
G{d}=S
%-----------------------------------------------------
% deleting the first output from the main array
%-----------------------------------------------------
A(idx,:) = []
B(idx,:) = []
end
C=[G{1};G{2}]
If i run the code i am getting In an assignment A(I) = B, the number of elements
in B and I must be the same.
Error in (line 47) Xi(i)=find(X(i,:))
Could anyone help me to overcome this error.
  3 Comments
Prabha Kumaresan
Prabha Kumaresan on 7 Jan 2018
Sorry. but the error in the code has not be overcomed which keeps me to ask again

Answers (1)

Tamir Suliman
Tamir Suliman on 7 Jan 2018
I think may be you should check the idx

This question is closed.

Tags

Community Treasure Hunt

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

Start Hunting!