필터 지우기
필터 지우기

Info

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

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

조회 수: 3 (최근 30일)
Prabha Kumaresan
Prabha Kumaresan 2017년 12월 12일
마감: MATLAB Answer Bot 2021년 8월 20일
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

답변 (1개)

Ahmos Sansom
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
Prabha Kumaresan
Prabha Kumaresan 2017년 12월 13일
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 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!

Translated by