在此示例中,如何重塑Matlab矩阵? [英] How to reshape matlab matrices for this example?

查看:109
本文介绍了在此示例中,如何重塑Matlab矩阵?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个40x16的矩阵或8个5x16的矩阵,一个在另一个矩阵下方,即垂直对齐. 我想从中得到一个5x128的矩阵,这样我就可以将8个5x16的矩阵水平对齐. 有没有一种有效/快速的方法(而不是硬编码的循环)来做到这一点?

I have a 40x16 matrix or 8 5x16 one below the other i.e. aligned vertically. I want to get a 5x128 matrix from that such that I align the 8 5x16 matrices horizontally. is there an efficient/quicker (rather than the hardcoded for loops) way to do this?

我想要完整的5x16矩阵.

I want the individual 5x16 matrices intact.

推荐答案

这应该有效.假设您的矩阵是A(40x16).

This should work. Suppose your matrix is A (40x16).

这是使用reshape的一种方式:

m = 5; n = 8; p = 16;
B = reshape(permute(reshape(A', p, m, n), [2 1 3]), m, n*p);

B将完整保留您的八个5x16矩阵.

B will have your eight 5x16 matrices next to each other, intact.

这是一种没有reshape的方法:

m = 5; n = 8;
B = cell2mat(arrayfun(@(i) A(m*(i-1)+1:m*i, :), 1:n, 'UniformOutput', false));

这篇关于在此示例中,如何重塑Matlab矩阵?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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