Borrar filtros
Borrar filtros

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

1 visualización (últimos 30 días)
Ji-hwan Hwang
Ji-hwan Hwang el 29 de Nov. de 2015
Comentada: Walter Roberson el 30 de Nov. de 2015
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 comentarios
Ji-hwan Hwang
Ji-hwan Hwang el 29 de Nov. de 2015
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 el 30 de Nov. de 2015
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?

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by