필터 지우기
필터 지우기

gathering two cells in confusion matrix

조회 수: 2 (최근 30일)
Salma Hassan
Salma Hassan 2020년 4월 2일
편집: Salma Hassan 2020년 4월 3일
If I have a 4*4 confusion matrix array [1 1 3 2; 1 0 2 1 ; 7 4 3 1; 5 6 3 7]. how can I combining both 2*2 regions are next to each other in order to constract a new array of 2*2 [3 8; 22 14]

채택된 답변

Fangjun Jiang
Fangjun Jiang 2020년 4월 2일
편집: Fangjun Jiang 2020년 4월 2일
If you have the Image Processing toolbox,
a=[1 1 3 2; 1 0 2 1 ; 7 4 3 1; 5 6 3 7];
fun = @(block_struct) sum(block_struct.data(:));
blockproc(a,[2 2],fun)
ans =
3 8
22 14
if Not,
a=rand(6,9);
RowBlock=2;
m=size(a,1)/RowBlock; % make sure m is an integer
ColBlock=3;
n=size(a,2)/ColBlock; % make sure n is an integer
b=mat2cell(a,repmat(RowBlock,1,m),repmat(ColBlock,1,n));
c=cellfun(@(x) sum(x(:)), b)
  댓글 수: 1
Salma Hassan
Salma Hassan 2020년 4월 3일
편집: Salma Hassan 2020년 4월 3일
actually the first one works well, however it takes a long time within a loop.
kindly, could you explain the second solution becouse i didn't understand it

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by