使用命令get_param(maskBlock,'MaskVariables')
,我得到一个如下所示的字符串:
'AB=@1;AC=@2;AD=@3;AE=@4;..AZ=@26;'
我想更改数字并将它们加 1 以获得:
'AB=@2;AC=@3;AD=@4;AE=@5;..AZ=@27;'
这是我编码的内容:
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 "letters=@"
它有效,但我几乎可以肯定有更好的方法来做到这一点。任何人都可以帮助我找到比使用 4 次命令更好的方法cellfun
吗?