# HG changeset patch # User Rik # Date 1643939178 28800 # Node ID 8b522a3591438e11c57dc0549dd3577addc880b6 # Parent b7c19b01cfc852e5beae823534ad43d364a4fe29# Parent 17a558588b8f784f41ce7c95bbfab997142b6af6 maint: merge stable to default. diff -r b7c19b01cfc8 -r 8b522a359143 libinterp/corefcn/find.cc --- 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))