在 MATLAB 中对数组进行整形 [英] Reshaping of Array in MATLAB

查看:27
本文介绍了在 MATLAB 中对数组进行整形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 32768*8 的数组,我想将其转换为 1*262144 的数组.我使用了 MATLAB 命令 reshape 但问题是 reshape 会按行更改矩阵,然后将其附加到列中.我也用过 (V:);功能,但它也与重塑相同,所以没用.

I have a 32768*8 array which I want to convert into a 1*262144 array. I have used the MATLAB command reshape but the problem is reshape changes the matrix row-wise and then appends it to the columns. I have also used the (V:); function but it also does the same as reshape so no use.

我希望保持二进制数据的完整性.所以0F 4B = 0000 1111 0100 1011...etc 应该是这样的,而不是像 reshape 命令那样做的.

I want that the binary data integrity is maintained. So 0F 4B = 0000 1111 0100 1011...etc should be like this and not otherwise as done by the reshape command.

有什么想法吗?谢谢!

推荐答案

您也可以先转置矩阵,然后调用 (:) 命令!如果您希望它成为行向量,请确保将向量转回.

You could also transpose your matrix first then invoke the (:) command too! Make sure you transpose your vector back if you want it to be a row vector.

MyMatrix = MyMatrix.';
MyVector = (MyMatrix(:)).';

为了语法正确(受 Dan 启发 - 见下文),我还使用了 .' 因为使用 ' 将调用 复杂转置.它不仅会转置您的向量,还会共轭您的元素.如果您想计算复矢量的幅度,这实际上非常有用,因为幅度平方的定义是 (a + ib)*(a - ib).如果我没记错的话,Loren Shure 的一篇文章(我记不清是哪一篇了)提到复数转置就是为此目的放在 MATLAB 中的.

Also to be syntactically correct (inspired by Dan - see below), I have also employed .' as using ' will invoke the complex transpose. Not only will it transpose your vector, it will also conjugate your elements as well. This is actually quite useful if you want to calculate the magnitude of a complex vector, as the definition of the magnitude squared is (a + ib)*(a - ib). If I remember correctly, an article by Loren Shure (I can't remember which one) mentioned that the complex transpose was placed in MATLAB for this very purpose.

但是,如果您的所有元素都是真实的,那么您可以使用 '.'.哪个都无所谓.

However, if all of your elements are real, then you can either use ' or .'. Doesn't matter which one.

这篇关于在 MATLAB 中对数组进行整形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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