Sizeof double float int etc
古いコメントを表示
Hello there,
I need to know how to find an equivallent function in Matlab to the sizeof function in c++.
For example, in c++ if I write sizeof(double) I would get the amount of memory needed to store a double.
I need something very similar with a matrix now. I will be storing bigger and bigger matrix and I need to find their size in the memory.
Could someone of you please help me?
all best,
:)
1 件のコメント
Yongjian Feng
2021 年 6 月 30 日
Did you try
whos
採用された回答
その他の回答 (3 件)
I need something very similar with a matrix now. I will be storing bigger and bigger matrix and I need to find their size in the memory.
Why? If you're trying to create an array to be filled in, just call a function like ones or zeros and tell it the size of the array you want to create (in terms of number of elements) and optionally the type. There's no need for you to know (or care) how much memory each element takes up in order to build the array.
A = ones(2, 3, 'int16')
B = zeros(5) % 5-by-5 double array
Fangjun Jiang
2021 年 6 月 30 日
Look at the .bytes returned by whos()
a=false(5);
aInfo=whos('a')
b=zeros(5);
bInfo=whos('b')
Kevin Holt
2024 年 8 月 16 日
編集済み: Kevin Holt
2024 年 8 月 16 日
Another option:
function n = sizeof(type)
dummy = zeros(1,type);
n = length(typecast(dummy,'int8'));
Then you can use it for various (non-complex) numeric types, e.g.
sizeof('double') returns 8
whos seems a little more general though.
カテゴリ
ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!