str2mat

Stacks text into a character matrix, padding rows with blanks.

Category: Language Fundamentals > Data Types

Syntax

S = str2mat(s1, s2, ...)

Returns a char matrix with one row per input.

Description

Shorter rows are padded on the right with blanks so that all rows have the same length. Empty inputs produce a row of blanks, which is the difference from strvcat, which drops them.

str2mat is an old function kept for compatibility; char does the same job and is preferred in new code.

Input arguments

s1, s2, ...
Character vectors or strings. Each becomes a row.

Output arguments

S
Character matrix whose width is that of the longest input.

Example

Padding to equal width

S = str2mat('one', 'three');
size(S)
S
size(str2mat('a', '', 'b'))
Output
ans = 1×2

     2     5
S = 2×5 char array

    'one  '
    'three'
ans = 1×2

     3     1

See also

char strvcat cellstr blanks