的使用命令get_param(maskBlock,'MaskVariables')
,我得到一个字符串,它看起来像这样:多次使用cellfun
'[email protected];[email protected];[email protected];[email protected];[email protected];'
我想改变的数字和顺序加1,他们得到:
'[email protected];[email protected];[email protected];[email protected];[email protected];'
这里我所编码:
strSplit = regexp(theStringFromGetParam , ';', 'split')'; % split the string at the ; to get multiple strings
str1 = cellfun(@(x) str2double(regexp(x,'(\d+)','tokens','once'))+1, strSplit, 'UniformOutput', false); % cell containing the last numbers
str2 = cellfun(@(x) regexp(x,'(\w+)(\W+)','tokens','once'), strSplit, 'UniformOutput', false); % cell containing everything that is not a number
str3 = cellfun(@(x) strcat(x{1}, x{2}), str2, 'UniformOutput', false); % join the two parts from the line above
str4 = cellfun(@(x,y) strcat(x,num2str(y)), str3, str1, 'UniformOutput', false); % join the number numbers with the "[email protected]"
它的工作原理,但我几乎可以肯定有一个更好的方式来做到这一点。任何人都可以帮助我找到比使用4次命令cellfun
更好的方法?
非常好!在接受最终答案之前,我会尽力去理解一切(其他答案)。 –