How to padleft with a variable number of digits?

27 Views Asked by At

I kknow I can pad a number up to 3 digits this way:

prematrix = sprintf('%03d', prematrix);

but what if I want a number of digits stored in a for example?

1

There are 1 best solutions below

0
On BEST ANSWER

I don't know Matlab, but just googled strcat and this should work (untested) for 12 zeros:

a='%0';
b='12';
c='d';
d=strcat(a,b,c);
prematrix = sprintf(d, prematrix);