So... I can understand matlab function handles and its purposes. But sometimes, when it gets too cryptic, I require help in further elaborating it. Take this example from the default MATLAB documentation, say:
f = @(x)x.^3-2*x-5;
I can also re-write it as:
function f(arg)
arg.^3 - 2*arg - 5;
end
Can anybody help out in deciphering the code below as previously mentioned from here? I don't need help in the default matlab functions. Just a little help in understanding the user-defined anonymous functions here..
applyToGivenRow = @(func, matrix) @(row) func(matrix(row, :))
applyToRows = @(func, matrix) arrayfun(applyToGivenRow(func, matrix), 1:size(matrix,1))'
% Example
myMx = [1 2 3; 4 5 6; 7 8 9];
myFunc = @sum;
applyToRows(myFunc, myMx)