When and why should I use cellfun in Matlab?
Date: 2022-10-17 15:48:05
question regarding the cellfun
function in MATLAB.
When / why should I use it, and when may I just as well drop it?
A simple example: Let's say I have a cell a
, and I want to find the average of all values in a
.
a{1} = [1 2;3 4]; a{2} = [1 2 3;4 5 6; 7 8 9];
My approach would be something like:
mean([a{1}(:); a{2}(:)])
What will the appropriate cellfun
version of this be, and is it any better?
I've tried doing something like this, (obviously not working):
mean_a = mean(cellfun(@mean, a,'UniformOutput',0))
Thanks!