MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1
mgrTitle = ['Harold A. Jorgensen '; ...
'Assistant Project Manager'; ...
'SFTware Corp. ']

mgrTitle =

3×25 char array

'Harold A. Jorgensen '
'Assistant Project Manager'
'SFTware Corp. '


  • Call the char function. If the character vectors have different lengths, char pads the
    shorter vectors with trailing blanks so that each row has the same number of
    characters.


mgrTitle = char('Harold A. Jorgensen', ...
'Assistant Project Manager', 'SFTware Corp.')

mgrTitle =

3×25 char array

'Harold A. Jorgensen '
'Assistant Project Manager'
'SFTware Corp. '

Combining Character Vectors Horizontally

To combine character vectors into a single row vector, use square brackets or the strcat
function.


  • Apply the MATLAB concatenation operator, []. Separate the input character vectors
    with a comma or a space. This method preserves any trailing spaces in the input
    arrays.


name = 'Thomas R. Lee';
title = 'Sr. Developer';
company = 'SFTware Corp.';

fullName = [name ', ' title ', ' company]

MATLAB returns

6 Characters and Strings

Free download pdf