How to separate numbers and text from a string

Hello,
i have string variable s = 'x 5.67 y 7.789';
i would like to read only numbers from the string.
requesting you to help me, how to separate numbers and text from the string.
Thanks & Regards Venkatapathi.P

 Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 28 Jan. 2014
Bearbeitet: Azzi Abdelmalek am 28 Jan. 2014

4 Stimmen

s = 'x 5.67 y 7.789'
out=str2double(regexp(s,'[\d.]+','match'))

4 Kommentare

Venkatapathi
Venkatapathi am 28 Jan. 2014
Thank you Azzi,
it solves my requirement
In case you have an example like this:
s = 'x.h 5.67 y 7.789 g4 j.23'
out=str2double(regexp(s,'\d+(\.\d+)?|\.\d+','match'))
How do you alter this to return the characters only in the string?
i.e. x.h y g j
Nader Virk
Nader Virk am 25 Feb. 2022
For string s, I appreciate if someone could help how to get only the chracters? Thanks!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Characters and Strings finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by