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

조회 수: 4 (최근 30일)
help me with matlab code
  댓글 수: 4
kaavya subramani
kaavya subramani 2016년 11월 22일
for eg=[1 2 3 4 5;6 7 8 9 10;1 12 13 14 15;16 17 18 19 20] my fist part contains [1 2 3 6 7 8],2nd part=[4 5 9 10],3rd part=[11 12 13 16 17 18],4th=[14 15 19 20],i need to find max value of each part also

댓글을 달려면 로그인하십시오.

채택된 답변

Guillaume
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
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
kaavya subramani
kaavya subramani 2016년 11월 22일
Thanks a lot sir,but i didnt get max value as per your code,also plz mention where to apply my data, in your code
KSSV
KSSV 2016년 11월 22일
For the random values max is as expected....A should be your data..

댓글을 달려면 로그인하십시오.


Bhanushnkar Gedela
Bhanushnkar Gedela 2019년 3월 15일
how to split the 16*64 matrix into 4 16*16 matrices

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by