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 件のコメント

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

サインインしてコメントする。

 採用された回答

Jan
Jan 2016 年 9 月 30 日

7 投票

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

その他の回答 (2 件)

Andrei Bobrov
Andrei Bobrov 2016 年 9 月 30 日

4 投票

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

5 件のコメント

Cheikh Ba SY
Cheikh Ba SY 2018 年 1 月 17 日
Thank you so much! It's very helpful
MOSTEFAI Messaoud
MOSTEFAI Messaoud 2020 年 3 月 19 日
Thank's
mayar elrakhawy
mayar elrakhawy 2022 年 4 月 26 日
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 2022 年 4 月 26 日
I need the value 43.3414 only
Jan
Jan 2022 年 4 月 26 日
str = 'v: 43.3414 m^3/kg';
a = sscanf(str, 'v: %f')
a = 43.3414

サインインしてコメントする。

Whashak Faeid
Whashak Faeid 2020 年 8 月 25 日

0 投票

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.

1 件のコメント

Stephen23
Stephen23 2020 年 8 月 25 日
>> str = '$11.75';
>> val = sscanf(str,'$%f')
val = 11.750

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeData Type Conversion についてさらに検索

製品

質問済み:

2016 年 9 月 30 日

コメント済み:

Jan
2022 年 4 月 26 日

Community Treasure Hunt

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

Start Hunting!

Translated by