Effacer les filtres
Effacer les filtres

Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

could anyone help me to execute the following code as i am unable to get the result.

3 vues (au cours des 30 derniers jours)
Prabha Kumaresan
Prabha Kumaresan le 12 Déc 2017
Clôturé : MATLAB Answer Bot le 20 Août 2021
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

Réponses (1)

Ahmos Sansom
Ahmos Sansom le 12 Déc 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 commentaires
Prabha Kumaresan
Prabha Kumaresan le 13 Déc 2017
thanks but in the command window it is getting displayed as matrix dimensions must agree in the command line Z=G.*S
Walter Roberson
Walter Roberson le 13 Déc 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?

Cette question est clôturée.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by