MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

Work with Space Characters


The blanks function creates a character vector of space characters. Create a vector of
15 space characters. Character vectors always are displayed between single quotation
marks.

chr = blanks(15)

chr =

' '

Insert a few nonspace characters in the middle of the blank character vector.

chr(6:10) = 'AAAAA'

chr =

' AAAAA '

You can justify the positioning of these characters to the left or right using the strjust
function:

chrLeft = strjust(chr,'left')

chrLeft =

'AAAAA '

chrRight = strjust(chr,'right')

chrRight =

' AAAAA'

Remove all trailing space characters with deblank:

chrDeblank = deblank(chr)

chrDeblank =

' AAAAA'

Remove all leading and trailing spaces with strtrim:

chrTrim = strtrim(chr)

6 Characters and Strings

Free download pdf