필터 지우기
필터 지우기

How to convert char into double?

조회 수: 719 (최근 30일)
Ivan Shorokhov
Ivan Shorokhov 2016년 9월 30일
댓글: Jan 2022년 4월 26일
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
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일
Str = '2.311.592 /';
Str(Str < '0' | Str > '9') = [];
Value = sscanf(Str, '%d');

추가 답변 (2개)

Andrei Bobrov
Andrei Bobrov 2016년 9월 30일
with str2double
out = str2double(regexp(val,'\d*','match'))
  댓글 수: 5
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일
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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by