Added function to get the number of bytes in a numeric type

main
David Protzman 2022-04-26 21:23:16 -04:00
rodzic df18420eaf
commit 3213764d68
1 zmienionych plików z 20 dodań i 0 usunięć

Wyświetl plik

@ -0,0 +1,20 @@
% Given a sample type (eg. 'single', 'int16', 'int8', etc) get how many bytes each I and Q value takes up
%
% @param sample_type MATLAB data type (ec. 'single', 'double', 'int16', etc) as a char array
% @return bytes Number of bytes required to represent the specified type
function [bytes] = get_bytes_per_sample(sample_type)
assert(ischar(sample_type) || isstring(sample_type), "Sample type must be a string or char array");
% Create an instance of the requested type
try
sample_type_ex = cast(1, sample_type);
catch
error('Failed to create value for type "%s"', sample_type);
end
% Get information about the variable created above
sample_type_info = whos('sample_type_ex');
bytes = sample_type_info.bytes;
end