Mercurial > octave
changeset 30709:8b522a359143
maint: merge stable to default.
author | Rik <rik@octave.org> |
---|---|
date | Thu, 03 Feb 2022 17:46:18 -0800 |
parents | b7c19b01cfc8 (current diff) 17a558588b8f (diff) |
children | 61134c8dd8e8 |
files | libinterp/corefcn/find.cc |
diffstat | 1 files changed, 13 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/find.cc Wed Feb 02 18:49:36 2022 +0100 +++ b/libinterp/corefcn/find.cc Thu Feb 03 17:46:18 2022 -0800 @@ -378,6 +378,10 @@ @end group @end example +If @var{x} is a multi-dimensional array of size m x n x p x @dots{}, @var{j} +contains the column locations as if @var{x} was flattened into a +two-dimensional matrix of size m x (n + p + @dots{}). + Note that this function is particularly useful for sparse matrices, as it extracts the nonzero elements as vectors, which can then be used to create the original matrix. For example: @@ -589,6 +593,15 @@ %! assert (j, jfull); %! assert (all (v == 1)); +%!test <*61986> +%! P = cat (3, eye(3), eye(3)); +%! loc = find (P); +%! [i, j, v] = find(P); +%! assert (loc, [1, 5, 9, 10, 14, 18]'); +%! assert (i, [1, 2, 3, 1, 2, 3]'); +%! assert (j, [1, 2, 3, 4, 5, 6]'); +%! assert (v, [1, 1, 1, 1, 1, 1]'); + %!assert <*53655> (find (false), zeros (0, 0)) %!assert <*53655> (find ([false, false]), zeros (1, 0)) %!assert <*53655> (find ([false; false]), zeros (0, 1))