MATLAB: Hi i have 1×36 cell,each cell contains 7×7 double, i need to divide each 7×7 equally into 4 halves and find max value in each halves,likewise for all 36 cells

digital image processing

help me with matlab code

Best Answer

yourcellarray = arrayfun(@(~) randi(20, 7), 1:36, 'UniformOutput', false) %demo data
cellfun(@(m) cellfun(@(quadrant) max(quadrant(:)), ... max of a quadrant
mat2cell(m, ... convert matrix in cell into cell of 4 quadrant
[ceil(size(m, 1)/2), floor(size(m, 1)/2)], ...
[ceil(size(m, 2)/2), floor(size(m, 2)/2)])), ...
yourcellarray, 'UniformOutput', false) %process each cell
edit: removed the 'UniformOutput', false from the inner cellfun since it's actually not needed. The output is thus a 1x36 cell array of 2x2 matrix instead of a 1x36 cell array of 2x2 cell arrays of scalars.