changeset 32989:9cbd0bbe7bd8 stable

doc: Document behavior of size when DIM arg exceeds actual number of dimensions (bug #65261) * data.cc (Fsize): Add explanation of case where DIM arg exceeds ndims (A). Add Example #5 to docstrings showing case of DIM arg exceeding ndims (A).
author Rik <rik@octave.org>
date Thu, 08 Feb 2024 11:32:11 -0800
parents 3eaaf9362cc3
children 749617dc63eb 88bff22985bd
files libinterp/corefcn/data.cc
diffstat 1 files changed, 12 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/data.cc	Thu Feb 08 08:40:58 2024 -0800
+++ b/libinterp/corefcn/data.cc	Thu Feb 08 11:32:11 2024 -0800
@@ -2722,7 +2722,9 @@
 first argument, the number of columns, dimension 2, is returned in the
 second argument, etc.  If there are more dimensions in @var{A} than there are
 output arguments, @code{size} returns the total number of elements in the
-remaining dimensions in the final output argument.
+remaining dimensions in the final output argument.  If the requested dimension
+@var{dim} is greater than the number of dimensions in @var{A}, @code{size}
+returns 1 (not 0).
 
 Example 1: single row vector output
 
@@ -2762,6 +2764,15 @@
 @end group
 @end example
 
+Example 5: number of elements in dimension > number of actual dimensions
+
+@example
+@group
+sz4 = size (ones (2, 3), 4)
+    @result{} sz4 = 1
+@end group
+@end example
+
 @seealso{numel, ndims, length, rows, columns, size_equal, common_size}
 @end deftypefn */)
 {