How to pad all numbers in array ?
이전 댓글 표시
How can I pad a vector of number with zeros ? I am able to do it with a for loop but I was wondering if there is a neater way to do it ?
For example,
a = [1 2 3 4 5];
b = sprintf('%06d',a);
gives me '000001000002000003000004000005'
I would like it to be [000001 000002 .....];
댓글 수: 1
Floating point numeric values do not store explicit leading zeros. Even if you typed them, the zeros have no mathematical significance:
>> [000001,000002]==[1,2]
ans =
1 1
채택된 답변
추가 답변 (1개)
Image Analyst
2016년 12월 11일
1 개 추천
What does that mean? If they're strings, fine -- you can have leading zeros. But if it's a number leading zeros are ignored, so printing or using 000003 will be just the same use using 3. So are you looking for a cell array? If so, see the FAQ: http://matlab.wikia.com/wiki/FAQ#What_is_a_cell_array.3F
카테고리
도움말 센터 및 File Exchange에서 MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!