Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

could anyone help me to fix the following issue

조회 수: 1 (최근 30일)
Prabha Kumaresan
Prabha Kumaresan 2018년 1월 7일
마감: Stephen23 2018년 1월 7일
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
Prabha Kumaresan
Prabha Kumaresan 2018년 1월 7일
Sorry. but the error in the code has not be overcomed which keeps me to ask again
Stephen23
Stephen23 2018년 1월 7일
duplicate

답변 (1개)

Tamir Suliman
Tamir Suliman 2018년 1월 7일
I think may be you should check the idx

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by