SPLIT - Splits a string (or a cell array of strings) into a cell array Syntax function B = split(A, sep) Reference "On the extension of trace norm to tensors" Ryota Tomioka, Kohei Hayashi, and Hisashi Kashima arXiv:1010.0789 http://arxiv.org/abs/1010.0789 Copyright(c) 2010 Ryota Tomioka This software is distributed under the MIT license. See license.txt
0001 % SPLIT - Splits a string (or a cell array of strings) into a cell array 0002 % 0003 % Syntax 0004 % function B = split(A, sep) 0005 % 0006 % Reference 0007 % "On the extension of trace norm to tensors" 0008 % Ryota Tomioka, Kohei Hayashi, and Hisashi Kashima 0009 % arXiv:1010.0789 0010 % http://arxiv.org/abs/1010.0789 0011 % 0012 % Copyright(c) 2010 Ryota Tomioka 0013 % This software is distributed under the MIT license. See license.txt 0014 0015 0016 function B = split(A, sep) 0017 0018 if ischar(A) 0019 A = {A}; 0020 end 0021 0022 B = cell(size(A)); 0023 0024 for i=1:prod(size(A)) 0025 s = findstr(A{i},sep); 0026 c = 1; 0027 B{i} = []; 0028 for j=1:length(s) 0029 B{i} = [B{i}, {A{i}(c:s(j)-1)}]; 0030 c = s(j)+1; 0031 end 0032 if (c<length(A{i})) 0033 B{i} = [B{i}, {A{i}(c:end)}]; 0034 end 0035 end 0036 0037 if prod(size(A))==1 0038 B = B{1}; 0039 end