hi i have 1x36 cell,each cell contains 7x7 double, i need to divide each 7x7 equally into 4 halves and find max value in each halves,likewise for all 36 cells
1 次查看(过去 30 天)
显示 更早的评论
help me with matlab code
4 个评论
采纳的回答
Guillaume
2016-11-22
编辑:Guillaume
2016-11-22
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.
更多回答(2 个)
KSSV
2016-11-22
clc; clear all ;
A = cell(1,36) ;
for i = 1:36
A{i} = rand(7) ;
end
%
B = cell(1,36) ;
for i = 1:36
A1 = NaN(8) ;
A1(1:7,1:7) = A{i} ;
% split to equal parts like +
A2(:,:,1) = A1(1:4,1:4) ;
A2(:,:,2) = A1(1:4,5:8) ;
A2(:,:,3) = A1(5:8,1:4) ;
A2(:,:,4) = A1(5:8,5:8) ;
% get maximum
B{i} = max(A2,[],3) ;
end
2 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!