如何将矩阵划分为相等的部分? [英] How to divide a matrix into equals parts?
问题描述
假设我有一个100x100的矩阵,我想将其分成10x10的相等部分.
Let's say I have a 100x100 matrix, I want to divide it into equal parts of 10x10.
问题在于输入矩阵可以是任何大小(但始终为mod 10).
我看了mat2cell
函数,但对于动态数量的零件,它似乎不起作用.
还是我错过了什么?
The problem is that the input matrix can be of any size (but always mod 10).
I looked at the mat2cell
function but it does not seem to work for a dynamic number of parts.
Or am I missing something?
推荐答案
您只需要确切地告诉mat2cell
您希望矩阵如何划分即可.如果您肯定两个方向上的比率总是10的倍数,那么(很)简单.假设X
是您要划分的矩阵,并且您想要在Y
中生成的单元格数组:
You just have to tell mat2cell
exactly how you want the matrix divided up. If you're positive that it is always going to be a multiple of 10 in both directions, then it is (fairly) simple. Assuming that X
is the matrix that you want to divide, and you want the resulting cell array in Y
:
Y = mat2cell(X, repmat(10,[1 size(X,1)/10]), repmat(10,[1 size(X,2)/10]));
这篇关于如何将矩阵划分为相等的部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!