How can I change a random element in a row of matrix?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Walter Roberson
le 30 Nov 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?
Réponses (0)
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!