Generate 10 numbers from matrix
Ältere Kommentare anzeigen
Say I have a matrix, v1, how would I be able to randomly generate 10 numbers within the existing matrix?
2 Kommentare
Do you mean that you have, for example, a 5x5 matrix such as
M = magic(5)
and you want to select 10 numbers from that matrix at random?
Can you select the same number twice, or all 10 should be from a different position?
How do you want the output? A vector of 10 numbers?
For you future reference, please understand that if you had spent more writing out a more complete, thoughtful question, we would not need to clarify what you need.
Ashante Isabella Bon
am 27 Sep. 2021
Akzeptierte Antwort
Weitere Antworten (1)
Based on what you've stated the following could be what you want to obtain:
v1 = randi(10, 5, 5) %#ok % Is existing matrix
IDX = randi([1, 10], 1, 10); % Randomly select indexes from the existing matrix
R = v1(IDX) % Randomly selected 10 numbers from v1
1 Kommentar
Ashante Isabella Bon
am 27 Sep. 2021
Kategorien
Mehr zu Random Number Generation finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!