MATLAB Examples

Codegen of Pack and Unpack Example

this example shows how to generate code from packData and unpackData


Set the input to an int8 1x2 vector

inputData = int8([-127 127]);
inputDataType = 'int8';
inputSize = 2;

Code Generation

Generate mex files from the packData and unpackData functions.

codegen('packData','-args',{int8([-127 127]),'int8',2});
codegen('unpackData','-args',{uint8([255 254]),coder.Constant('int8'),2});

Packing Data

Then pack the int8 vector into a uint8 1x2 vector using the mex version of the function packData_mex

packedData = packData_mex(inputData,inputDataType,inputSize)
packedData =

  255  254

Unpacking Data

To unpack the array of bytes and get the original int8 1x2 array we use the mex version of the function unpackData_mex

unpackedData = unpackData_mex(packedData,inputDataType,inputSize)
unpackedData =

 -127  127