apply a function to every element of a square matrix
Show older comments
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?
Accepted Answer
More Answers (2)
Jan
on 24 Sep 2012
Usually arrayfun is not required and wastes time:
x = rand(10, 10);
a = sin(x);
b = x .* x;
c = x .^ 2;
Image Analyst
on 24 Sep 2012
2 votes
Don't forget other cases, non-point processing cases, where vectorized solutions don't work, and I don't think arrayfun would work easily either. For example area processing operations like Sobel Filter, Savitkzy-Golay filter, morphological operations, adaptive filters, etc. Some of these have special functions to do them, but in general, for your custom operations, you can use functions like conv2(), imfilter(), nlfilter(), blockproc(), etc.
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!