linux - How do I filter to match or exclude certain fields in Octave? -


how filter match or exclude fields in octave?

using octave 3.0.5 on centos 5.8, need filter rows out of larger matrix various analyses.

for example, have array looks this:

a = { [ 0, 5, 32 ],       [ 0, 3, 2  ],       [ 1, 4, 13 ],       [ 1, 2, 32 ],       [ 2, 7, 99 ],       [ 2, 0, 42 ] }; 

now need able extract rows first value equal 1, or maybe second value greater 3, etc. i've tried reading documentation , searching examples, i'm not seeing it.

thanks!

you can use cellfun go through cell array , index (binary):

octave> cellfun (@(x) x(1) == 1 || x(2) > 3, a) ans =     1    0    1    1    1    0 

using example:

octave> a(cellfun (@(x) x(1) == 1 || x(2) > 3, a)) ans =  {   [1,1] =        0    5   32    [2,1] =        1    4   13    [3,1] =        1    2   32    [4,1] =        2    7   99  } 

an alternative may faster ditch cell array , use matrix instead (as long each cell in cell array have same size, matrix makes lot more sense, if need create multi-dimensional matrix). that's faster , simpler read:

octave> b = cell2mat (a); octave> b(b(:,1) == 1 | b(:,2) > 3, :) ans =      0    5   32     1    4   13     1    2   32     2    7   99 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -