MATLAB: Combine Strrep in one Line. MATLABstrrep Hi, is there any way that i Combine strrep as one line in my Code for different values. for example. a = strrep(a, 'x','y'); a = strrep(a, 'z','w'); Best Answer use replace with cell arrays,https://www.mathworks.com/help/matlab/ref/replace.htmla = 'abcxyz'old = {'x';'z'};new = {'y';'w'};a = replace(a, old,new) Related SolutionsMATLAB: Changing letters to other letters with regexprep You don't need regexprep, using ismember and indexing is simpler:>> str = 'a':'z'str = abcdefghijklmnopqrstuvwxyz>> old = 'bcd';>> new = 'abc';>> [X,Y] = ismember(str,old);>> str(X) = new(Y(X))str = aabcefghijklmnopqrstuvwxyzNote that this works efficiently for any characters, not just a limited subset. In order to use regexprep you would probably need to use a dynamic replacement expression. MATLAB: Reformatting Dates strrep is faster than regexprep:a = '12/01/2011';% Or a cell string also:% a = {'12/01/2011', '12/01/2012'};b = strrep(a, '/', ''); Related QuestionReplace the string a cell array with empty cellHow to remove single quotes using regexprepIs isstr not recommendedReplacing multiple lines with multiple lines in ascii fileConcatenate string to string array in efficient wayReplace multiple characters in a string with different characters
Best Answer