How to split a matrix in "submatrices"?
古いコメントを表示
How can i divide a matrix into submatrices of given dimensions in automatic way?
example:
data=reshape(1:88,11,8); %create a matrix
[mpixel,npixel]=size(data); %matrix's dimensions
m=2; %rows of the submatrix
n=3; %columns of the submatrix
v_w=floor(mpixel/m); %number of "vertical" submatrices
h_w=floor(npixel/n); %number of "horizontal" submatrices
cropdata=data(1:v_w*m,1:h_w*n);%crop matrix that can be diveded using that mxn submatrices
%
newdata=mat2cell(cropdata,[m m m m m],[n n]);
This code work but if I have bigger matrix I must continue to explicit [m m m...],[n n n...] in the last command and it's crazy. How can i use the command mat2cell with a smarter way?
4 件のコメント
Adam
2017 年 12 月 12 日
Why do you want to break your data up rather than just indexing into it and leaving it in one neat array?
Francesco Boari
2017 年 12 月 12 日
編集済み: Francesco Boari
2017 年 12 月 12 日
Image Analyst
2017 年 12 月 12 日
Why not just use blockproc() and let that handle the getting of the submatrices?
Francesco Boari
2017 年 12 月 13 日
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!