필터 지우기
필터 지우기

How can I choose a random row from a specific multidimensional array?

조회 수: 1 (최근 30일)
Hi,
I have a multidimensional array X=(50,9), and I want to choose a random row of 50 exist rows in an array.
First row in this array is just scalar numbering from 1 up to 50, I do not know if this can help to pick a random row based on the first row value or not!
Thanks in advance!

채택된 답변

Matt J
Matt J 2014년 4월 30일
randomRow=X(randi(50),:);
  댓글 수: 2
Abdulatif Alabdulatif
Abdulatif Alabdulatif 2014년 4월 30일
That was so quick : )
Thanks a lot.
Is it possible to replace the length of the array rows (50) with flexible statement to specify the number of rows in any array?
I just ask to generalise the answer rather than specified a specific value
Thanks again : )
Matt J
Matt J 2014년 4월 30일
Yes, see the size() command
[numRows,numCols]=size(X);

댓글을 달려면 로그인하십시오.

추가 답변 (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