Info
此问题已关闭。 请重新打开它进行编辑或回答。
could anyone help me how to overcome the following error
3 次查看(过去 30 天)
显示 更早的评论
G=rand(50,100)
C=rand(50,100)
N_G=15;%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(C(:,1))
e=sz
else
if d==1
e=randi([1 9])% select No of UE randomly
else
sz=length(C(:,1))
sz=ceil(sz/2)
e=randi([1 sz])% select No of UE randomly
end
end
%------------------------------------------
idx=randsample(1:size(C,1),e);
%------------------------------------------
% Getting arry G and C from random index
%------------------------------------------
for s=1:length(idx)
X(s,:) = C(idx(s),:)
Y(s,:) = G(idx(s),:)
Xi(s)=find(X(s,:))
end
X=[X(1:s,:)]
Y=[Y(1:s,:)]
%------------------------------------------
% Replacing
%------------------------------------------
non_0=sum(X)
non_0=repmat(non_0,s,1)
S=X
S(non_0 & X==0)=Y(non_0 & X==0);
Z{d}=S
%-----------------------------------------------------
% deleting the first output from the main array
%-----------------------------------------------------
G(idx,:) = []
C(idx,:) = []
end
W=[Z{1};Z{2};Z{3};Z{4};Z{5};Z{6};Z{7};Z{8};Z{9};Z{10};Z{11};Z{12};Z{13};Z{14};Z{15}]
If i run the following code i am getting Error (line 36) Xi(s)=find(X(s,:)) In an assignment A(I) = B, the number of elements in B and I must be the same.
Could anyone help me to solve the following issue.
0 个评论
回答(1 个)
Walter Roberson
2018-1-7
编辑:Walter Roberson
2018-1-7
You have
for s=1:length(idx)
X(s,:) = C(idx(s),:)
Y(s,:) = G(idx(s),:)
Xi(s)=find(X(s,:))
end
C has been assigned a 50 x 100 array. s is a scalar. idx(s) is a scalar. So C(idx(s),:) is going to be exactly one row out of C, so X(s,:) is going to be 1 x 100.
Now at the start, C is all non-zero because rand() never generates 0. So X(s,:) is going to start out all non-zero, so find(X(s,:)) is going to return all 100 indices because they are all non-zero locations. You try to assign those 100 indices to Xi(s) but Xi(s) only has room for a scalar.
You never use Xi again, so there is no obvious reason why you are computing Xi.
0 个评论
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!