strjust

Justifies the rows of a character matrix to the left, right or center.

Category: Language Fundamentals > Data Types

Syntax

T = strjust(S)

Right-justifies the rows of S.

T = strjust(S, type)

Justifies using type: 'right', 'left' or 'center'.

Description

strjust moves the leading and trailing blanks of each row without changing its characters or the size of the matrix. It is mainly used to align columns of numbers printed as text.

With 'center', if the blanks cannot be split evenly, the extra blank goes to the right.

Input arguments

S
Character matrix, padded with blanks.
type
'right' (default), 'left' or 'center'.

Output arguments

T
Character matrix of the same size in which the blanks have been moved.

Example

Three alignments

S = ['a  '; 'bb '];
strjust(S, 'right')
strjust(['  a'; ' bb'], 'left')
strjust(S, 'center')
Output
ans = 2×3 char array

    '  a'
    ' bb'
ans = 2×3 char array

    'a  '
    'bb '
ans = 2×3 char array

    ' a '
    'bb '

See also

strtrim deblank char pad