MATLAB Answers

0

How to select element from vector

Asked by Marat Zhe on 14 Jun 2018
Latest activity Commented on by Marat Zhe on 14 Jun 2018
Accepted Answer by KSSV
__Hi guys. I've got a vector (for exhample) A=[5,4,7,9,11,2,16] (generally vector may be bigger).
1. I want to take random element a1 from it (now vector A have size 1*7).
2. Then i want to take one more random element a2 from A with out of a1 !!
etc.
__So i want to take all elements from vector A.
__Can you give me a clue, how to do it in a simplest way.
__Thanks in advance!!

  0 Comments

Sign in to comment.

1 Answer

KSSV
KSSV 님의 답변 14 Jun 2018
 채택된 답변

A=[5,4,7,9,11,2,16] ;
idx = randperm(length(A)) ;
iwant = A(idx)

  3 Comments

__But how can i take one more random element a2 from vector A with out of a1 (you called it "iwant "). See opoint 2 of my question.
KSSV 14 Jun 2018
iwant is randomly arranged from A. Run a loop on iwant and pick.
Thank you very much KSSV. I've finally got what you meant.

Sign in to comment.