Ask an expert. Trust the answer.

Your academic and career questions answered by verified experts

Elegant vectorized version of CHANGEM (substitute values) - MATLAB

Date: 2022-09-19 15:43:16

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? 

Answers: 

 

A       = magic(3);
oldCode = [ 8  9];
newCode = [12 13];

[a,b] = ismember(A,oldCode);

A(a) = newCode(b(a));

I don't know changem, and I suspect the above will not fully cover its functionality (why else would TMW have introduced changem?), but well, it does what you asked :)


Why Matlabhelpers ?

Our Matlab assignment helpers for online MATLAB assignment help service take utmost care of your assignments by keeping the codes simple yet of high-quality. We offer the most reliable MATLAB solutions to students pursuing their Computer Science course from the Monash University, the University of Sydney, the University of New South Wales, the University of Melbourne; to name a few. Approach us today for best Matlab solutions online!

whatsApp order on matlabhelpers.com

telegram order on matlabsolutions.com