Split a table into columns with different delimiters
Afficher commentaires plus anciens
I used textscan to split a table into columns. But i need to use different delimiters for different places. For example:
str = '1,2,3,(one,5),(two,6,co)'
and i want it to be split as
{1},{2},{3},{(one,5)},{(two,6,co)}
The problem is the last two elements contain commas. If i use textscan, these commas in parenthesis will be counted as well. Any help is appreciated!
1 commentaire
Azzi Abdelmalek
le 2 Sep 2016
post how your data are stored
Réponses (1)
Star Strider
le 2 Sep 2016
This isn’t exactly what you asked for, but it’s close:
str='1,2,3,(one,5),(two,6,co)';
out1 = regexp(str, '\(|\)', 'split');
out2 = regexp(out1{1}, ',', 'split');
out = {out2{1:end-1} out1{[2 end-1]}}
out =
'1' '2' '3' 'one,5' 'two,6,co'
Catégories
En savoir plus sur Tables dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!