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 commentaires

KSSV
KSSV le 30 Sep 2016
Your character number got two points?
Jan
Jan le 30 Sep 2016
Which number do you expect as output?
Ivan Shorokhov
Ivan Shorokhov le 30 Sep 2016
@Jan Simon
I expect the whole number without dots and slashes, i.e. 2311592.
Thank you.

Connectez-vous pour commenter.

 Réponse acceptée

Jan
Jan le 30 Sep 2016

7 votes

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

Plus de réponses (2)

Andrei Bobrov
Andrei Bobrov le 30 Sep 2016

4 votes

with str2double
out = str2double(regexp(val,'\d*','match'))

5 commentaires

Cheikh Ba SY
Cheikh Ba SY le 17 Jan 2018
Thank you so much! It's very helpful
MOSTEFAI Messaoud
MOSTEFAI Messaoud le 19 Mar 2020
Thank's
mayar elrakhawy
mayar elrakhawy le 26 Avr 2022
I have the following char str= 'v: 43.3414 m^3/kg'
out = str2double(regexp(val,'\d*','match'))
out =
43 3414 3
how could it be converted to double without eleminating the decimal point ?
thanks in advance
mayar elrakhawy
mayar elrakhawy le 26 Avr 2022
I need the value 43.3414 only
str = 'v: 43.3414 m^3/kg';
a = sscanf(str, 'v: %f')
a = 43.3414

Connectez-vous pour commenter.

Whashak Faeid
Whashak Faeid le 25 Août 2020

0 votes

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.

Catégories

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by