why does matlab use 8 bytes to memorize a number like 1 for example
Afficher commentaires plus anciens
hi,
matlab uses 8 bytes to memorize a number like 1 as double as 2 bytes to memorize it as char?
Réponse acceptée
Plus de réponses (2)
Bhaskar R
le 3 Jan 2020
MATLAB software takes the defualt value storage memory for numeric a value is double precision floationg value that is 64 bit value in range -2^63 to 2^63-1. When you initialize any value by default it take takes 8 bytes of the memory. In single class memory take 4 bytes.If you want convert default double class value to single class you need to convert explicity as single
x = 1; % by default it is 64 bit(8 byte), double class
whos x
Name Size Bytes Class Attributes
x 1x1 8 double
x = cast(x, 'single') % or x = single(x) % converted 32 bit(4 byte), single class
whos x
Name Size Bytes Class Attributes
x 1x1 4 single
In case of character data type MATALB takes 2 byte of memory for each character
x = '1'; % x is character data type with 1 character
whos x
Name Size Bytes Class Attributes
x 1x1 2 char
x = '123456789'; % x is character data type with 9 character
whos x
Name Size Bytes Class Attributes
x 1x9 18 char
1 commentaire
Bhaskar R
le 3 Jan 2020
lou ham
le 3 Jan 2020
0 votes
1 commentaire
Walter Roberson
le 3 Jan 2020
You would typically use uint8 for that purpose. uint8 is an 8 bit unsigned integer, so 0 to 255. See also typecast()
Catégories
En savoir plus sur Data Type Conversion dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!