本节主要是熟悉matlab结构数组,该数据结构与python列表结构也可以类比
结构数组创建与赋值:
>> student(1).ID=101;
>> student(2).ID=102;
>> student(3).ID=103;
>> student(4).ID=104;
>> student(1).score=23;
>> student(2).score=42;
>> student(3).score=12;
>> student(4).score=100;
>> strct(student)
未定义与 'struct' 类型的输入参数相对应的函数 'strct'。
>> struct(student)
ans =
1x4 struct array with fields:
ID
score
>> B=stuct('name',123,'score',1254)
未定义与 'char' 类型的输入参数相对应的函数 'stuct'。
是不是想输入:
>> B=struct('name',123,'score',1254)
B =
name: 123
score: 1254
>> struct(B)
ans =
name: 123
score: 1254
>>
结构数组与单元数组互换
student =
1x4 struct array with fields:
ID
score
>> d=struct2cell(student)
d(:,:,1) =
[101]
[ 23]
d(:,:,2) =
[102]
[ 42]
d(:,:,3) =
[103]
[ 12]
d(:,:,4) =
[104]
[100]