필터 지우기
필터 지우기

select randomly "N" rows of a matrix?

조회 수: 10 (최근 30일)
Noe alvarado
Noe alvarado 2012년 4월 12일
how i can select randomly "N" rows of a matrix? for example
M =
[ a12, a12]
[ a21, a22]
[ a31, a32]
[ a41, a42]
For N=2
B =
[ a12, a12]
[ a31, a32]
[ a21, a22]

채택된 답변

Thomas
Thomas 2012년 4월 12일
try:
N=2; % no. of rows needed
M=rand(5) % generate a 5x5 matrix random
c=randperm(length(M),N)
B=M(c,:) % output matrix
  댓글 수: 4
Jan
Jan 2012년 4월 12일
@Noe, Then use: c = randperm(size(M, 1)); c = c(1:N);
Noe alvarado
Noe alvarado 2012년 4월 12일
thanks

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Random Number Generation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by