MATLAB中如何知道变量的大小
我在 MATLAB 中有变量,我已经使用 class()
检查了它们的类,但我也想知道它们在内存中占用的大小。更准确地说,我知道它们是 double 类型,并且我想确保它们是 32 位 double 而不是 64 位。
我使用的MATLAB版本是R2009b。
I have variables in MATLAB, I've checked their class using class()
but I also want to know the size that they take in the memory. More accurately, I know that they are of double type, and I want to make sure that they are 32-bit double and not 64-bit.
The version of the MATLAB I'm using is R2009b.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我编写了一个简单的便利函数来处理这个问题。用法是:
我运行的是R2007a,所以Java对象不返回大小的问题可能已经在后续版本中得到修复。这是代码:
I wrote a simple convenience function to handle just this problem. Usage is:
I run R2007a, so the problem of Java objects not returning sizes may have been fixed in subsequent releases. Here's the code:
您可以使用 whos 来获取描述等的结构数组things,每个变量的大小(以字节为单位)。
请注意,根据定义,双精度数是 64 位!
You can use whos to obtain an array of structures that describe, amongst other things, the size in bytes of each variable.
Note that a double is, by definition, 64-bit!
这将为您提供以兆字节为单位的大小,例如 MB=123.78
This will give you the size in megabytes, for example MB=123.78
我尝试增强“MatlabSorter”的简单功能来处理这个问题。用法仍然相同:
补充:
1.您可以说明您寻求哪种类型的返回 - b、kb、mb、tb 或 pb
2.您可以将结果作为变量获取,而无需将其打印在屏幕上
这是代码:
I tried to enhance ' MatlabSorter's ' simple function to handle this problem. Usage is still the same:
additions :
1.you can state which type of return you seek for - b, kb, mb, tb or pb
2.you can get the result as a variable without printing it on the screen
Here's the code:
另一种使用
whos
函数的班轮Yet another one liner using
whos
function您还可以显示工作区本身中变量的字节大小。
You can also show the byte size of variables in the workspace itself.