필터 지우기
필터 지우기

Left 6 digits of a 9 digit number that could be incomple

조회 수: 3 (최근 30일)
wesso Dadoyan
wesso Dadoyan 2017년 10월 8일
댓글: wesso Dadoyan 2017년 10월 8일
I have a column of 9 digit numbers that I want to trim to the left 6 digits.For example,931146104 should be 931146. Sometimes for small numbers the 9 digit column contains numbers that are fewer than 9 digit . for example 3100 should be 000003100 and the 6 digit number is consequently 000003. This manipulation is far beyond my basic matlab skills. I am wondering how to compute the 6 digit number in this context.

채택된 답변

Walter Roberson
Walter Roberson 2017년 10월 8일
편집: Walter Roberson 2017년 10월 8일
In vectorized form,
num2str( floor(n(:)/10^3), '%.06d')
  댓글 수: 3
Walter Roberson
Walter Roberson 2017년 10월 8일
Is that a problem? You have a fixed number of columns of output (that is, 6), and you did not say what data type you need to be output.
If you need a cell array of character vectors, then
cellstr( num2str( floor(n(:)/10^3), '%.06d') )

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

추가 답변 (1개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by