# I have a 25by3 matrix and i want to remove randomly 10 rows (I have already completed this part). The problem is that i want the original matrix which is 25by3 to be 15by3 after removing 10 rows. Thats my question

조회 수: 7(최근 30일)
Dennis_Pana 2015년 5월 17일
댓글: Steven Lord 2019년 8월 6일
Thats my code
X=[x1 x2 x3]; %25by3 matrix
%
k = randperm(size(X,1));
Ex_Ran= X(k(1:10),:)%extract 10 rows randomly

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

### 채택된 답변

Star Strider 2015년 5월 17일
Try this:
X=[x1 x2 x3]; %25by3 matrix
k = randperm(size(X,1));
Ex_Ran = X;
Ex_Ran(k(1:10),:) = [] %extract 10 rows randomly
##### 댓글 수: 7표시숨기기 이전 댓글 수: 6
Steven Lord 2019년 8월 6일
k is a reordering of the numbers between 1 and the number of rows in A.
You want a reordering of the numbers between 1 and the number of columns in A (which is the size of A in the second dimension) if you want to use it as a set of indices into the columns of B (which starts off as a copy of A.)

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

### 추가 답변(3개)

Andrei Bobrov 2015년 5월 18일
n = 10;
m = size(X,1);
out = X(rendperm(m,m-n),:);
##### 댓글 수: 0표시숨기기 이전 댓글 수: -1

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

Mark Stone 2015년 5월 18일
편집: Mark Stone 2015년 5월 18일
I show you this just so that you 'll be aware of the very handy setdiff function. it might not be as fast executing as the previous answer, but it is elegant.
X =[x1 x2 x3]; %25by3 matrix
k = randperm(size(X,1));
X = X(setdiff(1:25,k(1:10)),:);
Or you can make the left hand side a new variable, such as Y, if you want to preserve the original 25 by 3 matrix as is.
Y = X(setdiff(1:25,k(1:10)),:);
##### 댓글 수: 0표시숨기기 이전 댓글 수: -1

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

Murali Krishna 2015년 5월 18일
편집: Murali Krishna 2015년 5월 18일
To extract 10 rows of a given matrix
a=rand(25,3);%25*3 matrix
b=randperm(10);
c=a([b],:);
k=setdiff(a,c,'rows');
##### 댓글 수: 2표시숨기기 이전 댓글 수: 1
Murali Krishna 2015년 5월 18일
Thank u...

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

### 범주

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!