From 3213764d68986b33f6923e265a9a90361ac36a60 Mon Sep 17 00:00:00 2001 From: David Protzman Date: Tue, 26 Apr 2022 21:23:16 -0400 Subject: [PATCH] Added function to get the number of bytes in a numeric type --- matlab/updated_scripts/get_bytes_per_sample.m | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 matlab/updated_scripts/get_bytes_per_sample.m diff --git a/matlab/updated_scripts/get_bytes_per_sample.m b/matlab/updated_scripts/get_bytes_per_sample.m new file mode 100644 index 0000000..b6c4451 --- /dev/null +++ b/matlab/updated_scripts/get_bytes_per_sample.m @@ -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 +