Mercurial > octave
changeset 25563:a24b55da36ac
maint: merge stable to default.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 09 Jul 2018 11:33:25 -0700 |
parents | 5112f5b33dfd (current diff) 9277b77dd28f (diff) |
children | a461dedb833f |
files | |
diffstat | 1 files changed, 7 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/general/repelem.m Mon Jul 09 13:40:08 2018 -0400 +++ b/scripts/general/repelem.m Mon Jul 09 11:33:25 2018 -0700 @@ -299,20 +299,19 @@ else ## This works for a row or column vector. - ## idx2 output will be a row vector. ## Get ending position for each element item. idx_temp = cumsum (v); - ## Row vector with enough space for output - idx(1:idx_temp(end)) = 0; - ## Set starting position of each element to 1. - idx(idx_temp(1:end-1) + 1) = 1; + idx(idx_temp + 1) = 1; ## Set starting position of each element to 1. idx(1) = 1; + ## Row vector with proper length for output + idx = idx(1:idx_temp(end)); + ## with prepared index idx = (find (v != 0))(cumsum (idx)); @@ -427,6 +426,9 @@ %! assert (repelem ({1 0;0 -1}, 2, 3), %! {1 1 1 0 0 0;1 1 1 0 0 0;0 0 0 -1 -1 -1;0 0 0 -1 -1 -1}); +%!test <*54275> +%! assert (repelem (11:13, [1 3 0]), [11 12 12 12]); + ## nargin <= 1 error tests %!error (repelem ()); %!error (repelem ([]));