フィルターのクリア

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 Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by