Info
此问题已关闭。 请重新打开它进行编辑或回答。
could anyone help me to execute the following code as i am unable to get the result.
2 次查看(过去 30 天)
显示 更早的评论
UE=[2 4 6 8 10];
SC=[20 40 50 60 80];
for t=1:length(UE)
for r=1:length(SC)
G=rand(UE(t),SC(r));
B=zeros(UE(t),SC(r));
N=2;
for g=1:SC(r)
C= B(:,g);
zeroidx = find(~C);
replaceidx = zeroidx(randperm(numel(zeroidx), N-sum(C)));
C(replaceidx) = 1 ;
S(:,g) = [C];
end
Z = G .* S
end
end
0 个评论
回答(1 个)
Ahmos Sansom
2017-12-12
Not sure what this code does but you need to pre-allocate matrix S.
i.e.
UE=[2 4 6 8 10];
SC=[20 40 50 60 80];
for t=1:length(UE)
for r=1:length(SC)
G=rand(UE(t),SC(r));
B=zeros(UE(t),SC(r));
S = B;
N=2;
for g=1:SC(r)
C= B(:,g);
zeroidx = find(~C);
replaceidx = zeroidx(randperm(numel(zeroidx), N-sum(C)));
C(replaceidx) = 1 ;
S(:,g) = C;
end
Z = G .* S;
end
end
2 个评论
Walter Roberson
2017-12-13
Not when I copy and paste that code. That code executes for me.
I do notice, though, that you overwrite all of Z for each t and r value. If you are going to overwrite it all, why bother calculating it?
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!