time | calls | line |
---|
| | 1 | function c = cellstr(s)
|
| | 2 | %CELLSTR Create cell array of strings from character array.
|
| | 3 | % C = CELLSTR(S) places each row of the character array S into
|
| | 4 | % separate cells of C.
|
| | 5 | %
|
| | 6 | % Use CHAR to convert back.
|
| | 7 | %
|
| | 8 | % Another way to create a cell array of strings is by using the curly
|
| | 9 | % braces:
|
| | 10 | % C = {'hello' 'yes' 'no' 'goodbye'};
|
| | 11 | %
|
| | 12 | % See also STRINGS, CHAR, ISCELLSTR.
|
| | 13 |
|
| | 14 | % Copyright 1984-2013 The MathWorks, Inc.
|
| | 15 |
|
| 18 | 16 | if ischar(s)
|
| 18 | 17 | if isempty(s)
|
| | 18 | c = {''};
|
| 18 | 19 | elseif ~ismatrix(s)
|
| | 20 | error(message('MATLAB:cellstr:InputShape'))
|
| 18 | 21 | else
|
| 18 | 22 | numrows = size(s,1);
|
| 18 | 23 | c = cell(numrows,1);
|
| 18 | 24 | for i = 1:numrows
|
| 18 | 25 | c{i} = s(i,:);
|
| 18 | 26 | end
|
| 18 | 27 | c = deblank(c);
|
| 18 | 28 | end
|
| | 29 | elseif iscellstr(s)
|
| | 30 | c = s;
|
| | 31 | else
|
| | 32 | error(message('MATLAB:cellstr:InputClass'))
|
| | 33 | end
|