Mercurial > hg > octave-terminal
changeset 13300:ceda1714a4ad
Fix reversion introduced by changeset 86d18a3cc911.
* scripts/strings/strtrunc.m: Fix reversion in changeset 86d18a3cc911.
author | Ben Abbott <bpabbott@mac.com> |
---|---|
date | Sat, 08 Oct 2011 20:33:50 -0400 |
parents | e9f6a6edec42 |
children | 29a4d3b4211e |
files | scripts/strings/strtrunc.m |
diffstat | 1 files changed, 2 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/strings/strtrunc.m +++ b/scripts/strings/strtrunc.m @@ -39,7 +39,7 @@ ## Convoluted approach converts cellstr to char matrix, trims the character ## matrix using indexing, and then converts back to cellstr with mat2cell. ## This approach is 28X faster than using cellfun and recursive call to strtrunc - idx = cellfun ("length", s) > n; + idx = cellfun ("length", s) >= n; s(idx) = mat2cell (char (s(idx))(:, 1:n), ones (sum (idx), 1)); else error ("strtrunc: S must be a character string or a cell array of strings"); @@ -52,6 +52,7 @@ %!assert (strtrunc("abcdefg", 10), "abcdefg"); %!assert (strtrunc(char ("abcdef", "fedcba"), 3), ["abc"; "fed"]); %!assert (strtrunc({"abcdef", "fedcba"}, 3), {"abc", "fed"}); +%!assert (strtrunc({"1", "21", "321"}, 1), {"1", "2", "3"}) %% Test input validation %!error strtrunc ()