将Matlab矩阵分成几个相等的部分 [英] splitting a matlab matrix into several equal parts

查看:547
本文介绍了将Matlab矩阵分成几个相等的部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大小为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 of kmeans.

我知道如何做几乎所有事情(catkmeans等),但是我只是想找到一种将矩阵分为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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆