Используя команду 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
?