Info
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
could anyone help me to execute the following code as i am unable to get the result.
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Ahmos Sansom
el 12 de Dic. de 2017
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 comentarios
Walter Roberson
el 13 de Dic. de 2017
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?
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!