필터 지우기
필터 지우기

Convert a string to number

조회 수: 25 (최근 30일)
Lily
Lily 2014년 2월 5일
댓글: Lily 2014년 2월 6일
Hi, I want to convert a string into a number however I don't want to use str2num since I loose extra digits (see example below). Can I use some other MATLAB function?
data = 0.0782238;
s = str2num(data); %Don't want this since s = 0.0782 and I'm loosing three extra digits
  댓글 수: 4
Patrik Ek
Patrik Ek 2014년 2월 5일
Exactly. You could try
a=1.1111111;
a
b=2.2222222;
format long;
a+b
Lily
Lily 2014년 2월 6일
nice, thx :)

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

채택된 답변

Walter Roberson
Walter Roberson 2014년 2월 5일
str2num() does not lose those extra digits. Instead, you are not displaying the full width of the number. At the MATLAB command line give the command
format long g
and try your code again.

추가 답변 (1개)

Wayne King
Wayne King 2014년 2월 5일
편집: Wayne King 2014년 2월 5일
how about just using format long
data = '0.0782238';
data = str2num(data);
format long
data

카테고리

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