필터 지우기
필터 지우기

maintain 0 at the start of a number

조회 수: 2 (최근 30일)
Paul Murphy
Paul Murphy 2017년 12월 11일
답변: Star Strider 2017년 12월 11일
I have string of numbers that starts with a 0. I need to convert this to a number (str2num) but maintain the 0 at the start, as it represents a phone number.
example:
>> a = ('0123')
a =
0123
>> b = str2num(a)
b =
123
Any suggestions on how to do this so that my answer would be 0123?

채택된 답변

Star Strider
Star Strider 2017년 12월 11일
Try this:
a = ('0123');
b = sprintf('%04u', uint64(str2num(a)))

추가 답변 (1개)

Paul Murphy
Paul Murphy 2017년 12월 11일
Its a tricky one because i need to first convert the string to a number and then to uint64 as this is the format that my course grader wants the output.

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by