leading zeros on matrix variable

hello,
I have for example a matrix variable A = [ 1; 10, 100] and i want add leading zeros to obtain A=[001; 010;100]. This matrix is an exemple, i need to know how to do for all diferent matrix and not this matrix in specific!
Thank you !!

댓글 수: 1

John D'Errico
John D'Errico 2019년 4월 6일
편집: John D'Errico 2019년 4월 6일
Numbers conventionally don't have leading zeros. If you want to convert them to strings, then you can intentionally insert those leading zeros. But as numbers, they will not be displayed with leading zeros.

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

답변 (1개)

madhan ravi
madhan ravi 2019년 4월 6일

0 개 추천

Agree with John,
S = ""+A;
Max = max(cellfun('prodofsize',S));
Result = cellfun(@(x)regexprep(strjoin([""+zeros(1,Max-numel(x)) x]),' ',''),S,'un',0)

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

질문:

2019년 4월 6일

답변:

2019년 4월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by