blanks

Character vector made of space characters.

Category: Language Fundamentals > Data Types

Syntax

s = blanks(n)

Returns a 1-by-n char array of spaces.

Description

blanks is a convenient way to build padding or separators when assembling text by concatenation, as in ['Name:' blanks(4) 'Ana']. It is equivalent to repmat(' ', 1, n).

A negative or non-integer n is an error.

Input arguments

n
Nonnegative integer scalar.

Output arguments

s
Char row vector of n spaces; blanks(0) is empty.

Example

Padding text

s = ['[' blanks(3) ']']
length(s)
Output
s = '[   ]'
ans = 5

See also

deblank repmat strtrim pad