Split numbers in a cell into a few columns in V2011

4 vues (au cours des 30 derniers jours)
w23liang
w23liang le 11 Jan 2023
Réponse apportée : Voss le 11 Jan 2023
I have data that is not well formated:
"$# secid elform shrf qr/irid cst scoor nsm
2 5 0.866000 2 1
$# ts1 ts2 tt1 tt2
$ 2.439000 2.439000 1.939000 1.939000"
I read each line of the data into a cell in a matrix.
Now, I want to split the numbers in the cell to a different matrix.
For example, from " 2 5 0.866000 2 1"
To: [2, 5 , 0.866000, 2, 1]
It seems like "split" is the function for it, but it is only available after V2016, but I have V2011. Any idea how I can do this in the old version?
Thanks!

Réponse acceptée

Voss
Voss le 11 Jan 2023
You can try str2num:
str = ' 2 5 0.866000 2 1';
val = str2num(str)
val = 1×5
2.0000 5.0000 0.8660 2.0000 1.0000

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Produits


Version

R2011b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by