立即学习:https://edu.csdn.net/course/play/25039/288866?utm_source=blogtoedu
1.单元数组的建立
c={'大仙‘,’daxian’;[5 4 2 3 3],7}
c={1,1}
c={2,1}
c={2,2}=[]
2.使用函数创建数组
c=cell{3,3} %三行三列的数组 默认为空
c{1,1}=[1:3;2:5] %两行三列的数组
c{2,2}='daxian'
c{2,3}='yipeng'
c{2,1}=3
3.使用函数显示单元数组
celldisp{c} %单独显示每一个元素
celldiso{c,'daxiancell'} %改一个名称
4.图形化显示单元数组
figure;
out=cellplot(c,'legend') %图形化显示 带注释
5.单元数组的扩张和缩减
r={'大仙‘,’daxian';[1:6;2;7],5}
r{2.4}=3 %单元数组的扩张
r(1,:) %第一行元素
r(:,3)=[] %通过对整列赋值为空来删除
d={'dashen','daxian';[],44}
e={c,d} %单元数组的合并
c(2,:)=[] %通过对整行赋值删除第二行
6.将矩阵转换成单元数组
num2cell(2) %将矩阵转换成单元数组
iscell(a) %判断是不是单元数组
7.将单元数组转换成结构体变量
c={'daxian',170,20}
fields={'name','shengao','salary'} %结构体变量的成员
s=cell2struct(c,fields,2) %将单元数组转换为结构体变量
1.创建结构体变量
s1=struct('figure',{'big','little'},'yanse',{'blue'},'shuju',{[8 8 9,7 0 6][1:9]}
diyi=s1{1}
2.删除结构体成员变量
shanchu1=rmfield(s1,'yanse')
shanchu2=rmfield(s1,{'yanse','shuju'})
3.判断是不是结构体变量 判断是不是结构体变量成员
s=struct{'hehe',2,'haha',2}
f1=isstruct(s) %判断是不是结构体变量
f2=isfield(s,'acha')
f3=isfield(s,'hehe')
f4=isfield(s,{'hehe','haha','eaea','lala'})
4.按照某种方式获取成员变量
f1=fieldnames(s) %获取成员变量的名称
f2=orderfields(s) %按照成员变量的字母顺序排序
5.获取具体的某个实际成员变量的值
s=struct{'xingming',{'daxia','dashan'},'xingbie',{'nan','nv'},'fenshu',[67 90 99]
s(1).xingbie
s(1).fenshu(3)
pingjunfen=mean(s(1),fenshu)
max
6.使用函数获取结构体变量的值
s1=struct{'haha',8,'hehe',9}
f1=getfield(s1,'hehe')
7.使用函数来对成员变量重新赋值
s2=getfield(s1,'haha',9)
8.将结构体变量转换成单元数组
r=struct2cell(s)