-
Notifications
You must be signed in to change notification settings - Fork 24
/
split.m
48 lines (43 loc) · 1.12 KB
/
split.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
% split - splits a string (or a cell array of string) into a cell array
%
% Syntax
% B = split(A, sep)
%
% Reference
% "Estimation of low-rank tensors via convex optimization"
% Ryota Tomioka, Kohei Hayashi, and Hisashi Kashima
% arXiv:1010.0789
% http://arxiv.org/abs/1010.0789
%
% "Statistical Performance of Convex Tensor Decomposition"
% Ryota Tomioka, Taiji Suzuki, Kohei Hayashi, Hisashi Kashima
% NIPS 2011
% http://books.nips.cc/papers/files/nips24/NIPS2011_0596.pdf
%
% Convex Tensor Decomposition via Structured Schatten Norm Regularization
% Ryota Tomioka, Taiji Suzuki
% NIPS 2013
% http://papers.nips.cc/paper/4985-convex-tensor-decomposition-via-structured-schatten-norm-regularization.pdf
%
% Copyright(c) 2010-2014 Ryota Tomioka
% This software is distributed under the MIT license. See license.txt
function B = split(A, sep)
if ischar(A)
A = {A};
end
B = cell(size(A));
for i=1:prod(size(A))
s = findstr(A{i},sep);
c = 1;
B{i} = [];
for j=1:length(s)
B{i} = [B{i}, {A{i}(c:s(j)-1)}];
c = s(j)+1;
end
if (c<=length(A{i}))
B{i} = [B{i}, {A{i}(c:end)}];
end
end
if prod(size(A))==1
B = B{1};
end