help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: extracting rows in a matrix


From: Carlo Rossi
Subject: Re: extracting rows in a matrix
Date: Tue, 12 May 2009 23:07:22 +0000 (GMT)

hello,
 it doesn't work:
octave:16> extract_row = rand(nrows,1) < 0.2
extract_row =

   0
   0
   0
   0
   0

octave:17> B = A(extract_row, :)
B = [](0x4)

Yes, I need about 1/5; 400 rows = 400/5 rows; of course with 299/5 about 60 or 59.
Anyway I have to pick the row randomly. Your example it seems don't work good, I suppose...

thanks

--- Mer 13/5/09, Ivan Sutoris <address@hidden> ha scritto:
Da: Ivan Sutoris <address@hidden>
Oggetto: Re: extracting rows in a matrix
A: address@hidden
Cc: address@hidden
Data: Mercoledì 13 maggio 2009, 00:48

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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]