time | Calls | line |
---|
| | 1 | function t = strcat(varargin)
|
| | 2 | %STRCAT String horizontal concatenation.
|
| | 3 | % T = STRCAT(S1,S2,...), when any of the inputs is a string array,
|
| | 4 | % returns a string array by concatenating corresponding elements
|
| | 5 | % of S1,S2, etc. The inputs must all have the same size
|
| | 6 | % (or any can be a scalar).
|
| | 7 |
|
| | 8 | % Copyright 2016-2017 The MathWorks, Inc.
|
| | 9 |
|
| | 10 | % Convert string arguments, replacing <missing> values.
|
< 0.001 | 2 | 11 | isScalarMissing = false;
|
< 0.001 | 2 | 12 | isNonscalarMissing = false;
|
< 0.001 | 2 | 13 | for idx = 1:numel(varargin)
|
< 0.001 | 6 | 14 | if isstring(varargin{idx})
|
< 0.001 | 2 | 15 | mis = ismissing(varargin{idx});
|
< 0.001 | 2 | 16 | if any(mis(:))
|
| | 17 | if isscalar(varargin{idx})
|
| | 18 | isScalarMissing = true;
|
| | 19 | varargin{idx} = '';
|
| | 20 | else
|
| | 21 | isNonscalarMissing = true;
|
| | 22 | nonscalarMisIdx = mis;
|
| | 23 | str = varargin{idx};
|
| | 24 | str(nonscalarMisIdx) = '';
|
| | 25 | varargin{idx} = cellstr(str);
|
| | 26 | end
|
< 0.001 | 2 | 27 | else
|
< 0.001 | 2 | 28 | varargin{idx} = cellstr(varargin{idx});
|
< 0.001 | 2 | 29 | end
|
< 0.001 | 6 | 30 | end
|
< 0.001 | 6 | 31 | end
|
| | 32 |
|
| | 33 | % Use the cell or char method of strcat, converting back to string.
|
< 0.001 | 2 | 34 | try
|
0.009 | 2 | 35 | t = string(strcat(varargin{:}));
|
| | 36 | catch e
|
| | 37 | throw(e);
|
< 0.001 | 2 | 38 | end
|
| | 39 |
|
| | 40 | % Restore <missing> values.
|
< 0.001 | 2 | 41 | if isScalarMissing
|
| | 42 | % Everything is missing.
|
| | 43 | t(:) = missing;
|
< 0.001 | 2 | 44 | elseif isNonscalarMissing
|
| | 45 | % Entire value is missing.
|
| | 46 | t(nonscalarMisIdx) = missing;
|
< 0.001 | 2 | 47 | end
|
| | 48 |
|
< 0.001 | 2 | 49 | end
|
Other subfunctions in this file are not included in this listing.