Sum of matrix elements after using regexp
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
GEORGIOS BEKAS
il 24 Gen 2018
Risposto: Star Strider
il 24 Gen 2018
I wrote the following code to sum all number after locating numeric values from a string by using regexp.
s='2 groupd 40cell f'
g =regexp(s,'\d*','match')
g = cell2mat(g)
It gives an incorrect result: 240 --> instead of [2 40]
0 Commenti
Risposta accettata
Star Strider
il 24 Gen 2018
The numbers are strings, so cell2mat will concatenate them into one string array.
The solution is to use the str2double function if you want them as separate numbers:
g = str2double(g)
g =
2 40
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Characters and Strings in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!