www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/AddNewlineToCharacterVectorAndStringExample.m
%% Add Newline to Character Vector and String % Create a newline character with |newline| and concatenate it onto a % character vector. chr = 'Whose woods these are I think I know.'; chr = [chr newline 'His house is in the village though'] %% % Although |chr| displays on two lines, |chr| is a 1-by-73 character vector % that contains the two sentences, separated by a newline. % % Starting in R2016b, you can create strings using the |string| function. % Create a newline character. Then use |+| to concatenate the newline character % and more text onto the end of a string. str = string('In Xanadu did Kubla Khan'); str = str + newline + 'A stately pleasure-dome decree' %% % Although |str| displays on two lines, |str| is a 1-by-1 string.