结构数组的应用
结构数组有关函数

创建方法
- 直接法
student(1).ID=111;
>> student(2).ID=222;
>> student(3).ID=333;
student(1).Name='qwe';
>> student(2).Name='asd';
>> student(3).Name='zxc';
>> struct(student)
ans =
包含以下字段的 1×3 struct 数组:
ID
Name
- 函数法
结构数组名=struct(‘字段名’,对应字段名值,‘字段名’,对应字段名值,…)
student(4)=struct('ID',444,'Name','rty')
student =
包含以下字段的 1×4 struct 数组:
ID
Name
单元数组和结构数组转换
>>C=struct2cell(student);
>> C=[C(:,1),C(:,2),C(:,3),C(:,4)]
C =
2×4 cell 数组
{[111]} {[222]} {[333]} {[444]}
{'qwe'} {'asd'} {'zxc'} {'rty'}
注意:转换以后每一个数组名对应一个纵向量数组。
单元数组数据处理
>> s=0;
>> for i=1:4
s(i)=C{1,i}; %C中第一行第i列赋值
end,s,mean(s)
s =
111 222 333 444
ans =
277.5000
1934

被折叠的 条评论
为什么被折叠?



