Get number from a string

10 Ansichten (letzte 30 Tage)
GN3R8
GN3R8 am 10 Jun. 2022
Kommentiert: GN3R8 am 10 Jun. 2022
How do I get -0.966 from the string B as a number
B = α -0.966 ° OK 4.000 -15.000 ° 23.000 ° Freiwinkel
I'm missing the minus when I do this:
out_all= regexp(B, '\w*\d', 'Match');
out_all = out_all{1,1};
Radius = append(out_all{1},'.',out_all{2});

Akzeptierte Antwort

Stephen23
Stephen23 am 10 Jun. 2022
B = 'α -0.966 ° OK 4.000 -15.000 ° 23.000 ° Freiwinkel'
B = 'α -0.966 ° OK 4.000 -15.000 ° 23.000 ° Freiwinkel'
C = regexp(B,'[-+]?\d+\.?\d*', 'match')
C = 1×4 cell array
{'-0.966'} {'4.000'} {'-15.000'} {'23.000'}
V = str2double(C)
V = 1×4
-0.9660 4.0000 -15.0000 23.0000

Weitere Antworten (0)

Kategorien

Mehr zu Signal Processing Toolbox finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by