How to extract random elements from an array?

8 vues (au cours des 30 derniers jours)
Twisha Bansal
Twisha Bansal le 23 Déc 2019
For eg., I have a 1d array, d=[1;3;4;6;8;7;8;9;6;7] and I need to extract the first, third and sixth variable. How do I do that?
  1 commentaire
Stephen23
Stephen23 le 23 Déc 2019
"I need to extract the first, third and sixth variable."
There is only one variable, the vector d.
The vector d has elements, and most likely you are trying to extract those elements.

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 23 Déc 2019
d([1 3 6])
If you want 3 at random then,
d( randperm(length(d),3) )

Plus de réponses (1)

Badavath Swetha
Badavath Swetha le 28 Juin 2021
Modifié(e) : Badavath Swetha le 28 Juin 2021
d ([1 3 6])

Catégories

En savoir plus sur Elementary Math dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by