我如何prevent MATLAB从跌落"复杂"数组的属性? [英] How Do I Prevent MATLAB from Dropping the "complex" Attribute of an Array?

查看:141
本文介绍了我如何prevent MATLAB从跌落"复杂"数组的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的MATLAB code段,这就造成复数的两个数组,

The following MATLAB code snippet, which creates two arrays of complex numbers,

x = complex(1:2,0:1);
y = complex(zeros(1,2),0);
whos x y

打印

  Name      Size            Bytes  Class     Attributes

  x         1x2                32  double    complex   
  y         1x2                32  double    complex

预期。然而,在这两个附加声明,

as expected. However, after these two additional statements,

y(1) = x(1);
whos x y

以下会打印:

  Name      Size            Bytes  Class     Attributes

  x         1x2                32  double    complex   
  y         1x2                16  double

怎么能prevent而落下复杂的属性?

How can one prevent the complex attribute from being dropped?

有关备案,八度不一样。

For the record, Octave does the same.

在实践中, X 是函数的参数,其第一项恰好有一个零虚部,而 ]是被preallocated返回值。

In practice, x is a function argument whose first entry happens to have a zero imaginary part, and y is the return value that is being preallocated.

推荐答案

我想我找到了我一直在寻找在这个回答。总之,复数的阵列具有用于数据的两个存储器块:一个用于存储实部和一个用于存储虚部。最佳行动过程中应进行初始化来大小合适的double数组中,并让MATLAB增加对需求的第二个内存块。存储器的分配的数量为至多两个,而且似乎没有办法以降低它

I think I found what I was looking for in this answer. In sum, an array of complex numbers has two memory blocks for the data: one to store the real parts and one to store the imaginary parts. The best course of action should be to initialize y to an array of doubles of the right size and let MATLAB add the second memory block on demand. The number of memory allocations is at most two, and there seems to be no way to reduce it.

这篇关于我如何prevent MATLAB从跌落"复杂"数组的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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