필터 지우기
필터 지우기

Efficient way to divide array into tiles

조회 수: 2 (최근 30일)
Yi-xiao Liu
Yi-xiao Liu 2022년 10월 31일
댓글: Yi-xiao Liu 2022년 11월 2일
I use the following code to divide array into tiles
n=2;nrow=3;ncol=3;
A=reshape(1:36,6,6)
A = 6×6
1 7 13 19 25 31 2 8 14 20 26 32 3 9 15 21 27 33 4 10 16 22 28 34 5 11 17 23 29 35 6 12 18 24 30 36
A=mat2cell(A,zeros(nrow,1)+n,zeros(ncol,1)+n);
A=reshape(A,1,[]);
A=cellfun(@(x) x(:),A,"UniformOutput",false);
A=cell2mat(A)
A = 4×9
1 3 5 13 15 17 25 27 29 2 4 6 14 16 18 26 28 30 7 9 11 19 21 23 31 33 35 8 10 12 20 22 24 32 34 36
Now each column contains the element of each 2-by-2 tile.
The problem is when A is large and n is small the use of cell array creates significant overhead. Is there a more efficient way to do this?

채택된 답변

Matt J
Matt J 2022년 10월 31일
편집: Matt J 2022년 10월 31일
  댓글 수: 1
Yi-xiao Liu
Yi-xiao Liu 2022년 11월 2일
Excellent. Just what I need. Thanks!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by