Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String 基于字符串生成新对_String_Matlab - Fatal编程技术网

String 基于字符串生成新对

String 基于字符串生成新对,string,matlab,String,Matlab,我有一个字符串:str='HDEABGCF'。我怎样才能创造出第二个元素与第三个元素相结合,第四个元素与第五个元素相结合,第六个元素与第七个元素相结合的新组合呢 预期的输出应该是:result={'DE';'AB';'GC'}您可以滥用它,并确保以2为增量从字符串数组的第二个索引开始,一直到最后一个索引。对于每个索引,您将访问当前索引处的字符串和该点之后的下一个索引,然后使用uni=0标志确保输出为单元格数组: >> str='HDEABGCF'; >> result =

我有一个字符串:str='HDEABGCF'。我怎样才能创造出第二个元素与第三个元素相结合,第四个元素与第五个元素相结合,第六个元素与第七个元素相结合的新组合呢

预期的输出应该是:result={'DE';'AB';'GC'}

您可以滥用它,并确保以2为增量从字符串数组的第二个索引开始,一直到最后一个索引。对于每个索引,您将访问当前索引处的字符串和该点之后的下一个索引,然后使用
uni=0
标志确保输出为单元格数组:

>> str='HDEABGCF';
>> result = arrayfun(@(x) str([x x+1]), 2:2:numel(str)-1, 'uni', 0);
>> result

result = 

    'DE'    'AB'    'GC'
可能重复的