将Matlab矩阵分成几个相等的部分 [英] splitting a matlab matrix into several equal parts
问题描述
我有一个大小为64500x17
的矩阵.它代表检测到的texton功能,我必须使用它们才能找到kmeans
的5个质心.
I have a matrix of size 64500x17
. It represents detected texton features that I have to use to find 5 centroids for kmeans
.
我需要的是:
- 将此矩阵拆分为5个
12900x17
矩阵 - 找到方法
- 将它们连接到
5x17
矩阵中,以输入kmeans
的开始参数.
- split this matrix into 5
12900x17
matrices - find the means
- concatenate these into a
5x17
matrix to feed in to the start parameter ofkmeans
.
我知道如何做几乎所有事情(cat
,kmeans
等),但是我只是想找到一种将矩阵分为5部分或求和/除成所需大小的方法.
I know how to do almost everything (cat
, kmeans
, etc), but I am merely trying to find a method for splitting the matrix into 5 parts, or summing/dividing into the desired size.
除非绝对必要,否则我出于效率考虑禁止过度使用循环.
I am forbidden from overusing for loops (due to efficiency), unless absolutely necessary.
在其他问题上我找不到任何相关示例,因此,如果已回答此问题,请忍受.
I can't find any pertinent example in other questions, so if this has been answered, please bear with me.
推荐答案
您可以使用mat2cell
和此oneliner
You can use mat2cell
and this oneliner
C = mat2cell(A, repmat(12900, 5, 1), 17);
mat2cell
的第二个参数是矩阵的行拆分.
The second parameter to mat2cell
is the row split of the matrix.
现在C
是一个单元格数组:
Now C
is a cell array:
C =
[12900x17 double]
[12900x17 double]
[12900x17 double]
[12900x17 double]
[12900x17 double]
和部分矩阵可以按以下方式访问
and the partial matrices can be accessed as
C{1} etc.
这篇关于将Matlab矩阵分成几个相等的部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!