MATLAB: Modifying a string

strings

Hi,
I have a cell array where in each cell I have an alpha numeric number of IDs. I want to adjust this array in a way that if the ID is less than 6 digits (assume 777T) i want to add zeros before it to make it a 6 character ID (00777T). I have no clue how to do it.Any help is appreciated.

Best Answer

Use strjust().
a={'777T','123456','23A'};
b=char(a(:));
c=strjust(b,'right');
d=cellstr(c);
e=strrep(d,' ','0');
or make it shorter:
a={'777T','123456','23A'};
c=strjust(char(a(:)),'right');
e=strrep(cellstr(c), ' ','0');