help-octave
[Top][All Lists]
Advanced

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

Re: Extracting matrix rows that meet a condition


From: Juan Pablo Carbajal
Subject: Re: Extracting matrix rows that meet a condition
Date: Wed, 23 May 2012 22:13:44 +0200

On Wed, May 23, 2012 at 9:51 PM, Knof <address@hidden> wrote:
> Hi!
> I am pretty new to Octave and at the moment I have a problem that I cannot
> find a solution to.
> Basically I am working with a matrix that is three columns wide and is over
> a thousand rows long.
> What I need to do is to extract the rows that contain numbers that are
> either x < 0 or x > 1 and
> write those intact to a new *.txt file.
> Thank you in advance for any help!
>
> Knof
>
> --
> View this message in context: 
> http://octave.1599824.n4.nabble.com/Extracting-matrix-rows-that-meet-a-condition-tp4630112.html
> Sent from the Octave - General mailing list archive at Nabble.com.
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://mailman.cae.wisc.edu/listinfo/help-octave

Say your matrix is M.
Create logical indexes to extract the desired values
idx      = M < 0 | M > 1;
values =  M(idx);
[r c] = find (idx);

The variable values has the values that meet your condition. The
variables r and c contain the row and column (i.e. position in the
matrix) of those values.

To save to a ascii file use the function save
save --ascii "values.txt" values

-- 
M. Sc. Juan Pablo Carbajal
-----
PhD Student
University of Zürich
http://ailab.ifi.uzh.ch/carbajal/


reply via email to

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