[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: extracting rows in a matrix
From: |
Ivan Sutoris |
Subject: |
Re: extracting rows in a matrix |
Date: |
Wed, 13 May 2009 00:48:44 +0200 |
On Wed, May 13, 2009 at 12:03 AM, Carlo Rossi <address@hidden> wrote:
> Hello,
> I have a matrix A 450x10 and I need t extract randomly 1/5 of 500 rows and
> create with these rows another matrix B.
> Is there any function to do it? Any helps?
>
> thanks,
>
Hi
Try:
nrows = size(A,1);
extract_row = rand(nrows,1) < 0.2;
B = A(extract_row, :);
extract_row will be logical vector where approx. 1/5 of elements are
1, rest is 0. This is then used to create B by logical indexing from
A.
Of course, if you need to extract exactly 1/5 of rows, or resample
rows with replacement, this won't work.
Regards
Ivan Sutoris