I have got a 450 by 450 matrix. I need to reshape every 30 by 30 submatrix to become a 1 by 900 matrix. Therefore, there are 225 1 by 900 matrices. Then I have to group those 225 matrices to become a 225 by 900 matrix. At this moment I have got something like this to extract every 30 by 30 matrices.
for i=1:30:450
for j =1:30:450
G= m((i:i+29),(j:j+29));
end
end
But I have no ideas how to reshape those matrices to become 1 by 900 matrices to form a 225 by 900 matrix. Hope somebody can help, thank you.

댓글 수: 1

Azzi Abdelmalek
Azzi Abdelmalek 2013년 12월 14일
편집: Azzi Abdelmalek 2013년 12월 14일
Your code doesn't work. And you have to precise the order of your sub matrices (horizontal or vertical)

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

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 12월 14일
편집: Azzi Abdelmalek 2013년 12월 14일

0 개 추천

A=rand(450);
ii1=1:30:450;
ii2=1:30:450;
[x,y]=meshgrid(ii1,ii2);
B=arrayfun(@(ii,jj) reshape(A(ii:ii+29,jj:jj+29),1,[]),x,y,'un',0)
out=cell2mat(B(:))
another way is to switch x and y
B=arrayfun(@(ii,jj) reshape(A(ii:ii+29,jj:jj+29),1,[]),y,x,'un',0)

추가 답변 (1개)

Andrei Bobrov
Andrei Bobrov 2013년 12월 15일
편집: Andrei Bobrov 2013년 12월 15일

0 개 추천

From tricks by Peter J. Acklam:
s1 = size(A);
s2 = [30 30];
m = s1./s2;
p1 = reshape(A,s2(1),m(1),s2(2),[]);
p2 = permute(p1,[1 3 4 2]);
out = reshape(p2,prod(s1),[])';
or with bsxfun
s = size(A);
m = [30 30];
k = bsxfun(@plus,(0:m(1)-1)',(0:m(2)-1)*s(1));
l = bsxfun(@plus,(1:m(1):s(1))',(0:m(2):s(2)-1)*s(1))';
out = A(bsxfun(@plus,l(:),k(:)'));

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

질문:

2013년 12월 14일

편집:

2013년 12월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by