MATLAB Answers

Numeric extract from char

22 views (last 30 days)
Murugan C
Murugan C on 1 Oct 2020 at 12:32
Commented: Murugan C on 4 Oct 2020 at 12:36
Hello all, I need to extract numbers from char. For exp
("Acb2hea" == 10)
("Acb2hea1" >= 15)
("Acb2hea" <= 20)
I used regular expression but unble to get exact value which I want as below. I am getting like. 2 10 2 1 15 2 20
But Need output like 10 15 20

  0 Comments

Sign in to comment.

Accepted Answer

Stephen Cobeldick
Stephen Cobeldick on 1 Oct 2020 at 12:43
Edited: Stephen Cobeldick on 1 Oct 2020 at 12:44
>> regexp('("Acb2hea" == 10)','\<\d+\>','match')
ans =
'10'
>> regexp('("Acb2hea1" >= 15)','\<\d+\>','match')
ans =
'15'
>> regexp('("Acb2hea" <= 20)','\<\d+\>','match')
ans =
'20'
If required use str2double to convert to numeric.

  1 Comment

Murugan C
Murugan C on 4 Oct 2020 at 12:36
Thanks 😊

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by