MATLAB-通过垂直级联子矩阵重新排列矩阵 [英] MATLAB - re-arrange matrix by vertically concatenating submatrices
本文介绍了MATLAB-通过垂直级联子矩阵重新排列矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在执行以下任务时遇到麻烦: 假设一个3x6矩阵:
I am having trouble with the following task: Suppose a 3x6 matrix:
A =
0.2787 0.2948 0.4635 0.8388 0.0627 0.0435
0.6917 0.1185 0.3660 0.1867 0.2383 0.7577
0.6179 0.7425 0.0448 0.4009 0.9377 0.4821
我想做的就是将矩阵分成多个块,如下所示:
What I would like to do is to divide the matrix into blocks, like this:
A =
0.2787 0.2948 | 0.4635 0.8388 | 0.0627 0.0435
0.6917 0.1185 | 0.3660 0.1867 | 0.2383 0.7577
0.6179 0.7425 | 0.0448 0.4009 | 0.9377 0.4821
并垂直连接这些块以获得最终结果:
and vertically concatenate these blocks to get the final result:
0.2787 0.2948
0.6917 0.1185
0.6179 0.7425
0.4635 0.8388
0.3660 0.1867
0.0448 0.4009
0.0627 0.0435
0.2383 0.7577
0.9377 0.4821
我想如果我可以在这方面获得帮助,那么我也许可以 对任意矩阵A都可以做到 使用for循环时出现问题,但我正在寻找向量化解决方案.
I think if I can get help with this, then I can perhaps do it for arbitrary matrices A. I can solve the above problem using for-loops, but I am looking for a vectorised solution.
提前谢谢! N.
推荐答案
请考虑以下内容:
A = rand(3,6);
blkSz = 2;
C = mat2cell(A, size(A,1), blkSz*ones(1,size(A,2)/blkSz));
C = cat(1,C{:})
这假定size(A,2)
被blkSz
这篇关于MATLAB-通过垂直级联子矩阵重新排列矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文