MATLAB: How do seperate a string in different strings while not creating new strings for variables

seperate stringstring

Best Answer

For diversity of answers, here is another option (although I do not claim it is better than other answers!):
str = '# Donald-Duck [Father] Heuy [Son] Goofy Dewey [Son] Daisy-Duck Scrooge-McDuck [Uncle]';
% Get all the names, ignore the #
names = regexp(str,'\s','split');
names = names(2:end);
% Get index into output cell array for each name
ind = cumsum(cellfun('isempty',regexp(names,'[')));
% Make output
y = arrayfun(@(y) strjoin(names(ind==y),' '),1:max(ind),'uni',0);