sprintf

sprintf(format,v1,v2,...) returns a string with the values v1, v2,... as specified in format parameter.

Examples

>> x = 1:5

[x:1x5 double]

>> sprintf('line %d\n',x)#

line 1
line 2
line 3
line 4
line 5
>> sprintf('%3d',pi)# 

% specify minimun width

3 >> sprintf('%010.4f',pi)#

% complete minimun width with zeros and define precision

00003.1416 >> c = {'ABC'} sprintf('%s',c{:})#

% use %s for characters

ABC

See also

char | fprintf | num2str