MATLAB: Apply a function to every element of a square matrix

functionmatrix

I have a square matrix and I would apply a function to every element of that matrix in the way I get a new square matrix where every element is the result of the function.does it exist a function for the purpose?

Best Answer

Yes, arrayfun()
For example:
x = randn(10,10)+1i*randn(10,10);
y = arrayfun(@conj,x);
or
x = randn(10,10);
y = arrayfun(@(x) x.^2,x);