How can we split a line into two lines after n numbers or words?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Anjana Krishnan
le 8 Fév 2018
Modifié(e) : Walter Roberson
le 8 Fév 2018
If we have: lw = '27.3025 26.8384 27.3938 0.0000 26.9670 26.8788 26.0803 26.6281 27.1217 0.0000 27.4502' and I want to have: l1 = '27.3025 26.8384 27.3938 0.0000 26.9670', (having 5 numbers and l2 = '26.8788 26.0803 26.6281 27.1217 0.0000 27.4502', the remaining part of the line. Can this be done in a couple of lines in Matlab (not by taking each number/word at a time and forming the two lines)?
0 commentaires
Réponse acceptée
Walter Roberson
le 8 Fév 2018
Modifié(e) : Walter Roberson
le 8 Fév 2018
lw = '27.3025 26.8384 27.3938 0.0000 26.9670 26.8788 26.0803 26.6281 27.1217 0.0000 27.4502'
lwords = regexp(lw, '\s+', 'split');
l1 = strjoin(lwords(1:5), ' ');
l2 = strjoin(lwords(6:end), ' ');
or
lw = '27.3025 26.8384 27.3938 0.0000 26.9670 26.8788 26.0803 26.6281 27.1217 0.0000 27.4502'
tokens = regexp(lw, '(?<l1>(\S+\s+){5})(?<l2>.*)', 'names');
l1 = tokens.l1;
l2 = tokens.l2;
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Logical 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!