Applying a function to each matrix within a cell array in MATLAB can be accomplished using the cellfun function. For instance, to determine the median of each matrix within a cell array, the following commands can be issued:
temp={[1;2;3;4;5] [6;7;8;9;10]}
cellfun(@median,temp)
ans =
3 8
How can a similar operation be applied to the individual columns of the matrices within each cell of a cell array (for instance, the first column of the matrix within each cell)? For the following cell array, the desired output of applying the median function to the first column of the matrix in each cell is 3,9.
temp={[1 2;3 4;5 6] [7 8;9 10;11 12]}
How can the operation providing such an output be written? Lastly, how can this operation be performed such that the output from the Nth column of the matrix within each cell is stored in the Nth column of an output matrix?. In the simplified example above, for instance, 3,9 (the medians of the first columns of the matrices) would be stored in the first column of the output matrix; likewise, 4,10 (the medians of the second columns of the matrices) would be stored in the second column of the output matrix. The cell array (input) and desired median array (output) are shown below for convenience:
cell-1 cell-2
input = 1 2 7 8
3 4 9 10
5 6 11 12
output = 3 4
9 10
Thank you.