필터 지우기
필터 지우기

How can I change a random element in a row of matrix?

조회 수: 1 (최근 30일)
Ji-hwan Hwang
Ji-hwan Hwang 2015년 11월 29일
댓글: Walter Roberson 2015년 11월 30일
I want to change a random element in a row of matrix. example
A = ones(1,84)
I wish to change 6-8 column component to the randomly 2.
However, 2 of the 6-8 columns will be get out only once.
example A = [1,1,1,1,1,1,1,1,1,1,1,1,1...] ->change A = [1,1,1,1,1,2,1,1,1,1,1,1,2,1...]
I wrote the following code.
for q=6:6:84
if rand>0.5
A(1,q) =2;
end
end
for w=7:7:84
if rand>0.6
A(1,w)=2;
end
end
for e=8:8:84
if rand>0.7
A(1,w)=2;
end
end
But I did not produce the results you want.]
Ask for advice. Plz....
  댓글 수: 3
Ji-hwan Hwang
Ji-hwan Hwang 2015년 11월 29일
I want A matrix 6~8(multiple) column which change 1->2 .
A = ones(1,84);
column 6~8 is 1
A(1,6)=1,A(1,7)=1,A(1,8)=1 A(1,12)=1,A(1,14)=1, A(1,18)=1 ....
6 among 8 column select change 1->2
A(1,6)=2,A(1,7)=1,A(1,8)=1 A(1,12)=1,A(1,14)=2, A(1,18)=1 ....
understand?
Walter Roberson
Walter Roberson 2015년 11월 30일
Which columns are eligible to be changed?
Is it correct that out of all 84 columns, that exactly 6, 7, or 8 of them to be changed? So sum(A==2) would be 6, 7, or 8?
Or are you working in groups of columns, and out of each group of 8 columns, a certain number of them are to be changed randomly?

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by