说我有这样一个变量的字符串在MATLAB如下:添加一个字符串到每一行,在MATLAB字符串
this is the first line
this is the second line
this is the third line
我想在每个月初加一个固定的字符串线。例如:
add_substring(input_string, 'add_this. ')
将输出:
add_this. this is the first line
add_this. this is the second line
add_this. this is the third line
我知道我可以通过输入字符串循环做到这一点,但我要寻找一个更紧凑的(希望矢量)的方式来做到这一点,也许使用MATLAB内建的一个例如arrayfun
accumarray
。
输入字符串在技术上不是一个单元格数组,而是一个char字符串,但是我可以使用'[input_string,〜] = regexp(input_string,'\ n','split')将其转换为一个'' – 2012-01-18 16:07:39
'Strcat'工作也在'char'输入上。但是你仍然需要做这样的分割,因为多个字符串作为'char'被存储在一个2-d char矩阵中的单独行;看起来像你的输入是一个单一的多行字符串。 – 2012-01-18 16:26:56