Azzera filtri
Azzera filtri

How to convert char into double?

720 visualizzazioni (ultimi 30 giorni)
Ivan Shorokhov
Ivan Shorokhov il 30 Set 2016
Commentato: Jan il 26 Apr 2022
Hello everyone,
I have following char: "2.311.592 /" And I want to convert it to double and leave numbers only, I have tried to use
new = str2double(val);
But the output was NaN, what would you recommend me to do?
  3 Commenti
Jan
Jan il 30 Set 2016
Which number do you expect as output?
Ivan Shorokhov
Ivan Shorokhov il 30 Set 2016
@Jan Simon
I expect the whole number without dots and slashes, i.e. 2311592.
Thank you.

Accedi per commentare.

Risposta accettata

Jan
Jan il 30 Set 2016
Str = '2.311.592 /';
Str(Str < '0' | Str > '9') = [];
Value = sscanf(Str, '%d');

Più risposte (2)

Andrei Bobrov
Andrei Bobrov il 30 Set 2016
with str2double
out = str2double(regexp(val,'\d*','match'))
  5 Commenti
mayar elrakhawy
mayar elrakhawy il 26 Apr 2022
I need the value 43.3414 only
Jan
Jan il 26 Apr 2022
str = 'v: 43.3414 m^3/kg';
a = sscanf(str, 'v: %f')
a = 43.3414

Accedi per commentare.


Whashak Faeid
Whashak Faeid il 25 Ago 2020
How can I change '$11.75' this data type from char to doube.I want my output $11.75 as a double in data type.
Thanks in advance.

Categorie

Scopri di più su Data Type Conversion 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!

Translated by