How can I select a random element in a row of matrix?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
bkshn
il 27 Mag 2014
Commentato: Walter Roberson
il 29 Nov 2015
Hello
I want to select a a random element in a row and then I want to know the column of this element
Could you Help me?
Thanks
0 Commenti
Risposta accettata
Image Analyst
il 27 Mag 2014
Try this:
yourMatrix = magic(9) % Sample data
randomColumnNumber = randi(size(yourMatrix, 2), 1)
row = 3; % Whatever
% Get the value of the matrix at this location.
randomValueInRow = yourMatrix(row, randomColumnNumber)
0 Commenti
Più risposte (1)
rifat
il 27 Mag 2014
Assuming the data is in 'row'
col=1+floor(rand()*length(row)) % column number of the randomly selected element
element=row(col) % randomly selected element
2 Commenti
Ji-hwan Hwang
il 29 Nov 2015
you create is not resolved. I want to appear in one of two drainage Heat 6-8.
Walter Roberson
il 29 Nov 2015
Ji-hwan Hwang, I do not understand what you mean by "I want to appear in one of two drainage Heat 6-8" ?
If you want to select randomly from column 6 to 8, then
col = randi([6 8]);
element = row(col);
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!