[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: splitting array based on negative and positive values
From: |
Juan Pablo Carbajal |
Subject: |
Re: splitting array based on negative and positive values |
Date: |
Thu, 19 Jan 2012 17:35:20 +0100 |
On Thu, Jan 19, 2012 at 5:16 PM, Rick T <address@hidden> wrote:
> Greetings All
>
> I have and array and I'm trying to split out rows based on the positive and
> negative values in the 3rd column into their own separate arrays
> I know I can do a sortrows on the 3rd column but how does one split out rows
> based on the the negative and positive values of the 3rd column into there
> own array.
>
> Example of array:
> 1,2,-3
> 2,3,4
> 5,6,-7
> 8,9,-10
> 11,12,13
>
> 1st array split
> 1,2,-3
> 5,6,-7
> 8,9,-10
>
> 2nd array
> 2,3,4
> 11,12,13
>
> I'm using Octave 3.2.4 running under ubuntu 10.04 64bit
> Thanks
>
>
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://mailman.cae.wisc.edu/listinfo/help-octave
>
I assume you have your data in a matrix called A.
First, get the true-false matrix that says which row has last column negative
tf = A(:,end) < 0;
Then split your matrix
negA = A(tf,:);
posA = A(!tf,:);
Hope it helps.
--
M. Sc. Juan Pablo Carbajal
-----
PhD Student
University of Zürich
http://ailab.ifi.uzh.ch/carbajal/