extracting rows in a matrix
Carlo Rossi
serosole at yahoo.it
Tue May 12 18:07:22 CDT 2009
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 <ivan.sutoris at gmail.com> ha scritto:
Da: Ivan Sutoris <ivan.sutoris at gmail.com>
Oggetto: Re: extracting rows in a matrix
A: serosole at yahoo.it
Cc: help-octave at octave.org
Data: Mercoledì 13 maggio 2009, 00:48
On Wed, May 13, 2009 at 12:03 AM, Carlo Rossi <serosole at yahoo.it> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://www-old.cae.wisc.edu/pipermail/help-octave/attachments/20090512/c0260704/attachment-0001.html
More information about the Help-octave
mailing list