[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: array cross sections
From: |
Geraint Paul Bevan |
Subject: |
Re: array cross sections |
Date: |
Tue, 24 Aug 2004 19:52:34 +0100 |
User-agent: |
Mozilla Thunderbird 0.5 (X11/20040306) |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Sean Smith wrote:
| Anybody know how to get a sub array of elements that meet some
criteria, or
| a sub matrix, or conditioned on some other array?
| I am looking for something that sort of works like grep in perl.
|
| The only thing I can think of right now is a complecated system of sorting
| and truncating that I would like to avoid.
|
| Thanks,
| Sean
|
Have a look at the 'find' function. You can use it to extract elements
which meet some criteria. For example, to get all the elements of a 3x3
matrix which are less than 0.5:
octave> a = rand (3,3)
a =
~ 0.81472 0.83501 0.91338
~ 0.13548 0.12699 0.22103
~ 0.90579 0.96887 0.63236
octave> [i,j,v] = find (a .* (a<0.5))
i =
~ 2
~ 2
~ 2
j =
~ 1
~ 2
~ 3
v =
~ 0.13548
~ 0.12699
~ 0.22103
- --
Geraint Bevan
http://homepage.ntlworld.com/geraint.bevan
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
iEYEARECAAYFAkErjnIACgkQcXV3N50QmNNmHQCfXzw88bZhg7SOcSCVyUr2aOmE
g7sAniB0j0bsDSMLOIClc/A3SGbSRrof
=bGe5
-----END PGP SIGNATURE-----
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------