How to get Data type of workspace loaded variables and how add that datatypes using script?
Mostrar comentarios más antiguos
I have a .m files in that file many variales are created and loaded in workspace also but i want to add all the datatypes as bytes. can you tell me how to do?
Like uint8 as 1byte
uint16 as 2 byte so totally 3 bytes.
Thanks in advance.
6 comentarios
Steven Lord
el 15 de Abr. de 2021
How are you planning to use this information if you are able to obtain it? Counting how much memory is actually used can be a tricky question due to optimizations like copy-on-write.
A = rand(1, 10);
B = A; % This is not a copy yet. It references the same memory as A.
B(1) = 1; % Now it's a copy.
Steven Lord
el 16 de Abr. de 2021
That tells me what you want to do. But why do you need this information and do you care that your approach may not give you an accurate measurement of how much memory has actually been allocated?
Dhinesh K
el 16 de Abr. de 2021
Editada: Walter Roberson
el 16 de Abr. de 2021
Steven Lord
el 16 de Abr. de 2021
Okay, let's say for sake of argument that the sizes of the various properties added up to 420 bytes.
Why is that important? How are you going to use that information?
Dhinesh K
el 16 de Abr. de 2021
Respuestas (1)
Xingwang Yong
el 13 de Abr. de 2021
1 voto
s=whos;
numBytes = sum([s.bytes]);
14 comentarios
Dhinesh K
el 13 de Abr. de 2021
Stephen23
el 13 de Abr. de 2021
Do not multiply by 8.
Dhinesh K
el 13 de Abr. de 2021
Dhinesh K
el 13 de Abr. de 2021
Xingwang Yong
el 13 de Abr. de 2021
According to doc of uint8, it only takes 1 byte. And on my R2020a, it indeed takes 1 byte.
clear
var1=uint8(1);
whos
@Dhinesh K: it is unclear what the problem is. 8 bits is one byte.
"but matlab takes as default 8 bytes."
It is unclear how that is related to your question. The default variable class (double) uses exactly eight bytes:
x = 1; % double = 64 bits = 8 bytes
y = uint16(2); % 16 bits = 2 bytes
whos
and whos correctly returns the number of bytes for each variable. It is not clear what you expect to happen.
Dhinesh K
el 13 de Abr. de 2021
Dhinesh K
el 13 de Abr. de 2021
Dhinesh K
el 15 de Abr. de 2021
Stephen23
el 15 de Abr. de 2021
@Dhinesh K: please upload some sample data, and show the exact code that you are using.
Stephen23
el 15 de Abr. de 2021
You are only counting the number of bytes in the object handle. If you want to count the bytes in all attributes/properties of the object itself, then try one of the methods outlined in the links I showed you.
Dhinesh K
el 15 de Abr. de 2021
Categorías
Más información sobre Creating, Deleting, and Querying Graphics Objects en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!