fast array substitution

a function to substitute entries of an array using rules From(i) -> To(i)
Updated 1 Jul 2014

View License

Given a numerical array A and two arrays From and To of equal size, we would like to make substitution From(i)->To(i) in the array A for every i.
If the number of values to substitutes (numel(From)) is small, one can use a vectorized code to substitute the values one-by-one. However, this is too costy if there are too many substitutions. In this case, the provided function uses a different algorithm. It sorts the array A and the substitution rules and then it does one non-vectorized sweep of the inputs. Finally, we restore the original order and shape of A.

Cite As

Ondrej Budac (2024). fast array substitution (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2014a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Find more on Matrices and Arrays in Help Center and MATLAB Answers
Tags Add Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes

added an icon