# HG changeset patch # User Ben Abbott # Date 1318120430 14400 # Node ID ceda1714a4ad1189708626aef14a82a05ce8fc3d # Parent e9f6a6edec428f36ae2282698cfb76b8115023cf Fix reversion introduced by changeset 86d18a3cc911. * scripts/strings/strtrunc.m: Fix reversion in changeset 86d18a3cc911. diff --git a/scripts/strings/strtrunc.m b/scripts/strings/strtrunc.m --- 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 ()