MATLAB Answers

Picking a random row of a matrix

6 views (last 30 days)
Phillip Smith
Phillip Smith on 27 Nov 2019
Edited: James Tursa on 27 Nov 2019
Hello, I have a matrix Y that's nx2. Say in this case n=5. (n can only take the values 3,5 or 8 but I guess that doesn't matter)
Y =
9 2
10 2
9 3
9 4
10 4
I want to randomly choose on of these rows so I can use them as coordinates!
Many thanks,
Phill

  0 Comments

Sign in to comment.

Accepted Answer

James Tursa
James Tursa on 27 Nov 2019
Edited: James Tursa on 27 Nov 2019
k = randi(size(Y,1)); % the random row index
Y(k,:) is the random row

  0 Comments

Sign in to comment.

More Answers (0)

Sign in to answer this question.