Mercurial > octave
changeset 30280:7835150ba175
repelem.m: produce row output for scalar input (bug #61412)
* repelem.m: Reverse vector handling so that output is a row for a
scalar input.
* NEWS: Note change for matlab compatibility.
author | Nicholas R. Jankowski <jankowski.nicholas@gmail.com> |
---|---|
date | Tue, 02 Nov 2021 11:00:45 -0400 |
parents | 68aa1e839578 |
children | 4730becad0b1 |
files | NEWS scripts/general/repelem.m |
diffstat | 2 files changed, 8 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/NEWS Wed Nov 10 13:14:48 2021 -0500 +++ b/NEWS Tue Nov 02 11:00:45 2021 -0400 @@ -255,6 +255,9 @@ compatibility the `print_struct_array_contents` internal variable is set to true. +- The function `repelem` now produces a row vector output when the input is +a scalar. + ### Alphabetical list of new functions added in Octave 7 * `cospi`
--- a/scripts/general/repelem.m Wed Nov 10 13:14:48 2021 -0500 +++ b/scripts/general/repelem.m Tue Nov 02 11:00:45 2021 -0400 @@ -191,12 +191,12 @@ ndims (x), ndims (x) + 1, nargin); endif - if (iscolumn (x)) + if (isrow (x)) + ## element values repeated R times in a scalar or row vector + retval = x(ones (R, 1), :)(:).'; + else ## element values repeated R times in a col vector retval = x.'(ones (R, 1), :)(:); - else - ## element values repeated R times in a row vector - retval = x(ones (R, 1), :)(:).'; endif elseif (isvector (x) && isvector (R)) @@ -347,6 +347,7 @@ %!assert (repelem ([i; -i], 2), [i; i; -i; -i]) ## nargin == 2 tests +%!assert (repelem (2, 6), [2 2 2 2 2 2]) %!assert (repelem ([-1 0 1], 2), [-1 -1 0 0 1 1]) %!assert (repelem ([-1 0 1]', 2), [-1; -1; 0; 0; 1; 1]) %!assert (repelem ([-1 0 1], [1 2 1]), [-1 0 0 1])