Picking a random row of a matrix

조회 수: 2 (최근 30일)
Phillip Smith
Phillip Smith 2019년 11월 27일
편집: James Tursa 2019년 11월 27일
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

채택된 답변

James Tursa
James Tursa 2019년 11월 27일
편집: James Tursa 2019년 11월 27일
k = randi(size(Y,1)); % the random row index
Y(k,:) is the random row

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by