time | Calls | line |
---|
| | 1 | function len = strlength(s)
|
| | 2 | %STRLENGTH Lengths of text elements.
|
| | 3 | % L = STRLENGTH(STR) returns the number of characters in STR.
|
| | 4 | %
|
| | 5 | % STR can be a string array, a character vector, or a cell array of
|
| | 6 | % character vectors. If STR is a string array or cell array, then L is a
|
| | 7 | % numeric array, where each element is the number of characters in the
|
| | 8 | % corresponding element of STR.
|
| | 9 | %
|
| | 10 | % Example:
|
| | 11 | % STR = "data.xlsx";
|
| | 12 | % strlength(STR)
|
| | 13 | %
|
| | 14 | % returns
|
| | 15 | %
|
| | 16 | % 9
|
| | 17 | %
|
| | 18 | % Example:
|
| | 19 | % STR = 'annualReport.docx';
|
| | 20 | % strlength(STR)
|
| | 21 | %
|
| | 22 | % returns
|
| | 23 | %
|
| | 24 | % 17
|
| | 25 | %
|
| | 26 | % Example:
|
| | 27 | % STR = ["funds.xlsx";"demo.ppt"];
|
| | 28 | % strlength(STR)
|
| | 29 | %
|
| | 30 | % returns
|
| | 31 | %
|
| | 32 | % 10
|
| | 33 | % 8
|
| | 34 | %
|
| | 35 | % See also LENGTH.
|
| | 36 |
|
| | 37 | % Copyright 2014-2017 The MathWorks, Inc.
|
| | 38 |
|
< 0.001 | 52 | 39 | narginchk(1, 1);
|
| | 40 |
|
< 0.001 | 52 | 41 | if ischar(s) && (isempty(s) || isrow(s))
|
< 0.001 | 36 | 42 | len = numel(s);
|
< 0.001 | 16 | 43 | elseif iscell(s)
|
< 0.001 | 16 | 44 | len = zeros(size(s));
|
< 0.001 | 16 | 45 | for idx = 1:numel(s)
|
< 0.001 | 72 | 46 | element = s{idx};
|
< 0.001 | 72 | 47 | if ischar(element) && (isempty(element) || isrow(element))
|
< 0.001 | 72 | 48 | len(idx) = numel(element);
|
| | 49 | else
|
| | 50 | error(firstInputErrorMessage);
|
< 0.001 | 72 | 51 | end
|
< 0.001 | 72 | 52 | end
|
| | 53 | else
|
| | 54 | error(firstInputErrorMessage);
|
< 0.001 | 52 | 55 | end
|
< 0.001 | 52 | 56 | end
|
Other subfunctions in this file are not included in this listing.