#include "quit.h"
#include "defun-dld.h"
#include "error.h"
#include "gripes.h"
#include "oct-obj.h"
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 DO_INT_BRANCH | ( | INTT | ) |
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().
DEFUN_DLD | ( | find | , | |
args | , | |||
nargout | ||||
) |
Definition at line 335 of file find.cc.
References arg(), octave_value::array_value(), octave_value::bool_array_value(), octave_value::char_array_value(), octave_value::complex_array_value(), DO_INT_BRANCH, error(), error_state, find_nonzero_elem_idx(), octave_value::float_array_value(), octave_value::float_complex_array_value(), gripe_wrong_type_arg(), octave_value::index_vector(), octave_value::is_bool_type(), octave_value::is_complex_type(), octave_value::is_integer_type(), octave_value::is_perm_matrix(), octave_value::is_real_type(), octave_value::is_single_type(), octave_value::is_sparse_type(), octave_value::is_string(), panic_impossible, octave_value::perm_matrix_value(), print_usage(), octave_value::sparse_bool_matrix_value(), octave_value::sparse_complex_matrix_value(), octave_value::sparse_matrix_value(), idx_vector::unmask(), xisinf(), and xround().
octave_value_list find_nonzero_elem_idx | ( | const Sparse< T > & | v, | |
int | nargout, | |||
octave_idx_type | n_to_find, | |||
int | direction | |||
) |
Definition at line 86 of file find.cc.
References Sparse< T >::cidx(), Sparse< T >::cols(), Sparse< T >::columns(), Sparse< T >::data(), Sparse< T >::nnz(), panic_impossible, Array< T >::resize(), Matrix::resize(), Sparse< T >::ridx(), and Sparse< T >::rows().
octave_value_list find_nonzero_elem_idx | ( | const PermMatrix & | v, | |
int | nargout, | |||
octave_idx_type | n_to_find, | |||
int | direction | |||
) |
Definition at line 228 of file find.cc.
References PermMatrix::cols(), PermMatrix::data(), PermMatrix::is_col_perm(), panic_impossible, Array< T >::resize(), Matrix::resize(), and PermMatrix::rows().
octave_value_list find_nonzero_elem_idx | ( | const Array< T > & | nda, | |
int | nargout, | |||
octave_idx_type | n_to_find, | |||
int | direction | |||
) |
Definition at line 40 of file find.cc.
References Array< T >::dims(), Array< T >::find(), Array< T >::index(), Array< T >::is_empty(), Array< T >::length(), Array< T >::numel(), Array< T >::rows(), and Array< T >::xelem().
Referenced by DEFUN_DLD().