1.定义结构体数组

比如定义一个二维的结构体数据DemoStructArray,需要先定义数组长度及类型,如下:

DemoStructArray(2) = struct;

这表示定义DemoStructArray是个二维的结构体数组,但是结构体成员还未确定。matlab工作空间如下:

2. 定义结构体的成员

这里定义DemoStructArray的成员,也定义成结构体,如下:

DemoStructArray(1).Q95MaxInfo = struct;
DemoStructArray(1).Q95MaxInfo.Q95Val = 0;
DemoStructArray(1).Q95MaxInfo.FilePath = '';
DemoStructArray(1).Q98MaxInfo = struct;
DemoStructArray(1).Q98MaxInfo.Q98Val = 0;
DemoStructArray(1).Q98MaxInfo.FilePath = '';

DemoStructArray(2).Q95MaxInfo = struct;
DemoStructArray(2).Q95MaxInfo.Q95Val = 0;
DemoStructArray(2).Q95MaxInfo.FilePath = '';
DemoStructArray(2).Q98MaxInfo = struct;
DemoStructArray(2).Q98MaxInfo.Q98Val = 0;
DemoStructArray(2).Q98MaxInfo.FilePath = '';

maltab工作空间变量如下:

更多推荐