I have an arbitrary variable X, and I would like apply a function and get as the output the number of bits X takes up. I know that I can use 'whos', but I want a usable output of the number of bits of X.
Is there any (built-in) function that can do this in MATLAB?
If you look to whos documentation.
You can do this :
variableStruct = whos('x');
nbByte = variableStruct.bytes
If the variable doesn't exist, you structure is empty.
EDIT
With subref, you can do it in one liner like this :
byte = subsref(whos('x'),struct('type','.','subs','bytes'));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With