My question is pretty much entirely in the title. I am curious about how matlab stores data and specifically how much data an nxn array takes to store. Is each element of the array an individual 8 byte double so the size is 8*n^2 bytes?

 채택된 답변

James Tursa
James Tursa 2023년 11월 4일
편집: James Tursa 2023년 11월 4일

0 개 추천

The data is held in contiguous memory, so yes for a full real double an NxN matrix would take 8*N^2 bytes for the data. Then there is a variable header that contains info such as class, dimensions, data pointers, etc. That takes an additional 132(?) bytes or so per variable. The actual header amount can vary from release to release, and I haven't checked lately what it is currently.

댓글 수: 4

Alec Bledsoe
Alec Bledsoe 2023년 11월 4일
Okay. Just making sure I understand this, if I were to create an array A, where A = randi([0 9], n), I would get a variable that takes up 8*n^2+132 bytes?
Yes, but the header amount doesn't show up under whos even though it is there. E.g.,
n = 10;
A = randi([0 9], n);
whos
Name Size Bytes Class Attributes A 10x10 800 double cmdout 1x33 66 char n 1x1 8 double
Alec Bledsoe
Alec Bledsoe 2023년 11월 4일
Got it thank you. How do I check the header size?
Walter Roberson
Walter Roberson 2023년 11월 4일
https://www.mathworks.com/matlabcentral/answers/2010767-struct-function-in-matlab
My answer there analyzes struct.
96 bytes to describe a variable. 8 bytes pointer to the data. Another 64 bytes to hold the variable name.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

제품

릴리스

R2023b

질문:

2023년 11월 4일

댓글:

2023년 11월 4일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by