Help splitting string using strsplit
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Richard Youden
le 4 Jan 2019
Modifié(e) : madhan ravi
le 7 Jan 2019
I have a large set of data which is presented as a string, for example:
1;2;3;4;5;6;7;8 etc...
I use:
strsplit(data,';')
and that breaks everything up into individual cells.
However I have found an issue with some data. My logger is 100% reliable so sometimes I get data which looks like:
;;;;;6;7;8 etc...
Using the strsplit command I get:
NaN 6 7 8
What I'd like is
NaN NaN NaN NaN NaN 6 7 8
Any suggestions?
0 commentaires
Réponse acceptée
Geoff Hayes
le 4 Jan 2019
Modifié(e) : Geoff Hayes
le 4 Jan 2019
strsplit(data, ';', 'CollapseDelimiters', false)
so that the consecutive empty delimiters are not collapsed into one cell.
0 commentaires
Plus de réponses (2)
madhan ravi
le 4 Jan 2019
Modifié(e) : madhan ravi
le 7 Jan 2019
str=';;;;;6;7;8';
expr=';';
C=str2double(regexp(str,expr,'split')) % edited after Jan’s comment
%[~,c]=regexp(str,expr,'match','split');
%Result=cellfun(@str2double,c)
Gives:
Result =
NaN NaN NaN NaN NaN 6 7 8
2 commentaires
Voir également
Catégories
En savoir plus sur Cell Arrays dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!