Defines | Functions

find.cc File Reference

#include "quit.h"
#include "defun-dld.h"
#include "error.h"
#include "gripes.h"
#include "oct-obj.h"
Include dependency graph for find.cc:

Go to the source code of this file.

Defines

#define DO_INT_BRANCH(INTT)

Functions

 DEFUN_DLD (find, args, nargout,"-*- texinfo -*-\n\ @deftypefn {Loadable Function} {@var{idx} =} find (@var{x})\n\ @deftypefnx {Loadable Function} {@var{idx} =} find (@var{x}, @var{n})\n\ @deftypefnx {Loadable Function} {@var{idx} =} find (@var{x}, @var{n}, @var{direction})\n\ @deftypefnx {Loadable Function} {[i, j] =} find (@dots{})\n\ @deftypefnx {Loadable Function} {[i, j, v] =} find (@dots{})\n\ Return a vector of indices of nonzero elements of a matrix, as a row if\n\ @var{x} is a row vector or as a column otherwise. To obtain a single index\n\ for each matrix element, Octave pretends that the columns of a matrix form\n\ one long vector (like Fortran arrays are stored). For example:\n\ \n\ @example\n\ @group\n\ find (eye (2))\n\ @result{} [ 1; 4 ]\n\ @end group\n\ @end example\n\ \n\ If two outputs are requested, @code{find} returns the row and column\n\ indices of nonzero elements of a matrix. For example:\n\ \n\ @example\n\ @group\n\ [i, j] = find (2 * eye (2))\n\ @result{} i = [ 1; 2 ]\n\ @result{} j = [ 1; 2 ]\n\ @end group\n\ @end example\n\ \n\ If three outputs are requested, @code{find} also returns a vector\n\ containing the nonzero values. For example:\n\ \n\ @example\n\ @group\n\ [i, j, v] = find (3 * eye (2))\n\ @result{} i = [ 1; 2 ]\n\ @result{} j = [ 1; 2 ]\n\ @result{} v = [ 3; 3 ]\n\ @end group\n\ @end example\n\ \n\ If two inputs are given, @var{n} indicates the maximum number of\n\ elements to find from the beginning of the matrix or vector.\n\ \n\ If three inputs are given, @var{direction} should be one of \"first\" or\n\ \"last\", requesting only the first or last @var{n} indices, respectively.\n\ However, the indices are always returned in ascending order.\n\ \n\ Note that this function is particularly useful for sparse matrices, as\n\ it extracts the non-zero elements as vectors, which can then be used to\n\ create the original matrix. For example:\n\ \n\ @example\n\ @group\n\ sz = size (a);\n\ [i, j, v] = find (a);\n\ b = sparse (i, j, v, sz(1), sz(2));\n\ @end group\n\ @end example\n\ @seealso{nonzeros}\n\ @end deftypefn")
template<typename T >
octave_value_list find_nonzero_elem_idx (const Sparse< T > &v, int nargout, octave_idx_type n_to_find, int direction)
octave_value_list find_nonzero_elem_idx (const PermMatrix &v, int nargout, octave_idx_type n_to_find, int direction)
template<typename T >
octave_value_list find_nonzero_elem_idx (const Array< T > &nda, int nargout, octave_idx_type n_to_find, int direction)

Define Documentation

#define DO_INT_BRANCH (   INTT  ) 
Value:
else if (arg.is_ ## INTT ## _type ()) \
        { \
          INTT ## NDArray v = arg.INTT ## _array_value (); \
          \
          if (! error_state) \
            retval = find_nonzero_elem_idx (v, nargout, \
                                            n_to_find, direction);\
        }

Referenced by DEFUN_DLD().


Function Documentation

DEFUN_DLD ( find  ,
args  ,
nargout   
)
template<typename T >
octave_value_list find_nonzero_elem_idx ( const Sparse< T > &  v,
int  nargout,
octave_idx_type  n_to_find,
int  direction 
)
octave_value_list find_nonzero_elem_idx ( const PermMatrix v,
int  nargout,
octave_idx_type  n_to_find,
int  direction 
)
template<typename T >
octave_value_list find_nonzero_elem_idx ( const Array< T > &  nda,
int  nargout,
octave_idx_type  n_to_find,
int  direction 
)
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines