利用char, str2mat, strvcat创建多行字符串数组

用专门函数char , str2mat , strvcat创建多行字符串数组示例。

1.char('str1', 'str2',...)

Convert to character array (string)转换成字符串数组,空字符串是有效的。

示例:
S1=char('This string array','', 'has two rows.')  
S1 =
This string array


has two rows.      

2.str2mat  (新版本中被char替代)

Form blank-padded character matrix from strings 

(将字符串转化成有空白填充的字符矩阵)

syntax

S = str2mat(T1, T2, T3, ...)

example

x = str2mat('36842', '39751', '38453', '90307');

whos x
  Name      Size         Bytes  Class

  x         4x5             40  char array

x(2,3)

ans =

    7

3.strvcat
strvcat会将空字符串忽略掉,这是和char、str2mat的区别。
example:
S3=strvcat('123', '', '456') 
S3 =
123
456

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

原文地址:https://www.cnblogs.com/jiangkejie/p/5823750.html