given a cell array of strings, I want to build one regexprep rule, so that different string types are replaced by a certain number. I.e:
my_cell = {'ok', 'ok', 'bad', 'broken', 'bad', 'broken', 'ok'};
I know how to replace each string type one by one, i.e:
my_cell = regexprep(my_cell,'ok$','1');
but ideally I would like to build one rule, so that ok will be replaced with 1, bad will be replaced with 0 and broken will be replaced with -1.
any hints on how to do this?
There’s documentation here: http://www.mathworks.co.uk/help/techdoc/ref/regexprep.html
It gives the syntax as:
s = regexprep('str', 'expr', 'repstr')It also says: “If both expr and repstr are cell arrays of strings, then expr and repstr must contain the same number of elements, and regexprep pairs each repstr element with its matching element in expr.”
Therefore you could try something like this:
(Untested)