string to double when string contains a / sign.
조회 수: 3 (최근 30일)
이전 댓글 표시
I have a string like this: '2/10'. I want to convert it to a double, so 0.2 how can I do this?
댓글 수: 0
채택된 답변
Guillaume
2016년 4월 20일
You can use str2num which eval the string, instead of str2double. Note that since it evaluates the string any valid matlab expression in the string will be executed, therefore don't blindly pass user input to str2num:
>>str2num('2/10')
ans =
0.20000
%this will delete all files on your drive!
str2num('rmdir(''c:\'', ''s'')')
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!