How to apply arrayfun on a 3D matrix?
22 views (last 30 days)
I have the following matrix:
size(A) = [64 64 1000];
I'd like to apply the following function on each frame, along the 3rd dimension.
lasca_func = @(x)(mean2(x)/std2(x));
How can I do this via arrayfun, and not through for-loop?
Thanks in advance!
Stephen23 on 25 Jul 2017
Edited: Stephen23 on 25 Jul 2017
"How can I do this via arrayfun, and not through for-loop?"
You can't, because arrayfun operates on each element of an array. You cannot tell it to operate along specific dimensions of an array. An alternative would be to split the array into a cell array and then call cellfun, but this would be slower than using a preallocated loop.
Unless you have a gpuArray the simplest solution is to use mean and std, and specify the dimension:
>> A = rand(64,64,1000);
>> Z = mean(A,3)./std(A,0,3);