zero pad on the left of this vector ,a=[1 2 3] in matlab

You can use the sprintf function to format the elements of your vector as a string with leading zeros. Here's an example code snippet:

main.m
a = [1 2 3];
a_padded = sprintf('%02d ', a);
disp(a_padded)
60 chars
4 lines

Output:

main.m
01 02 03 
10 chars
2 lines

Note that %02d specifies a decimal integer with minimum width 2 and leading zeros. The space after %02d adds a space after each element of the vector. If you don't want the trailing space, you can use a_padded(1:end-1) to remove the final character.

related categories

gistlibby LogSnag