In Matlab 2012b, there is a changem
function that allows you to substitute elements of a matrix with other values specified by a set of keys:
Substitute values in data array
Is there an elegant/vectorized way to do the same if I don't have the Mapping toolbox?
Vectorized implementation of
CHANGEM
withbsxfun
,max
Sometime back, I was made to write a customized vectorized version of
changem
implemented withbsxfun
andmax
as part of a much bigger problem. The referenced solution could be found here. Then, following few links I saw this post and thought it could be posted here as a solution for an easy find among future readers as also because this problem exclusively asks for an efficient and vectorized version ofchangem
. So, here's the function code -The syntax used in the custom version follows the same syntax as in
changem.m
-Unfortunately, I think you need a FOR loop. But it's pretty straightforward:
Yes, use
ismember
:I don't know
changem
, and I suspect the above will not fully cover its functionality (why else would TMW have introducedchangem
?), but well, it does what you asked :)