Read Structure From C header file

バージョン 1.0.2 (3.49 KB) 作成者: Lior Alpert
This function can create a Matlab structure that match a structure from C header file (.h file)
ダウンロード: 464
更新 2020/9/2

ライセンスの表示

This function reads a structure from a C header file and convert it to Matlab structure.

[MatlabStruct] = Read_C_Struct_From_header(h_FileName);
[MatlabStruct] = Read_C_Struct_From_header(h_FileName, OutStructName);

h_FileName - The name of the h file (e.g. LogStruct.h)
OutStructName - The name of the structure that will be extructed from the header file. If the name doesn't exist in the file or wasn't input by the user, the last structure in the file will be output

The function also supports nested structures.
The struct can be defined by either 'typedef' or 'struct', but doesn't support mix definitions.
for example:

typedef struct {
unsigned long long Var1;
char Var2;
float Var3[8];
} my_struct;

Or:

struct my_struct {
unsigned long long Var1;
char Var2;
float Var3[8];
};

The function is currently limit to the following data types:
[double, single, int8, uint8, int16, uint16, int32, uint32, int64, uint64]
['char', 'short', 'long', 'int', 'long long', 'float', 'double', 'unsigned char', 'unsigned short', 'unsigned long', 'unsigned int', 'unsigned long long']

--------------------------

This function is very useful when trying o read a binary file that was created by C\C++ code. It can be used to to create a structue for the 'cstruct' function:
AJ Johnson (2020). cstruct (https://www.mathworks.com/matlabcentral/fileexchange/4048-cstruct), MATLAB Central File Exchange. Retrieved April 26, 2020.

引用

Lior Alpert (2026). Read Structure From C header file (https://jp.mathworks.com/matlabcentral/fileexchange/75210-read-structure-from-c-header-file), MATLAB Central File Exchange. 取得日: .

MATLAB リリースの互換性
作成: R2020a
R2016b 以降のリリースと互換性あり
プラットフォームの互換性
Windows macOS Linux
バージョン 公開済み リリース ノート
1.0.2

Small fix that prevent potential error with some comments in the C header

1.0.1

1. I have added support in 'bool' type
2. Add an example

1.0.0