结构:
查询grade值:student.grade
输入第二个同学的信息
查询第二个同学的第二个成绩:student(2).grade(1,2)
结构函数:
cell2struct
fieldnames
getfield
isfield
isstruct
orderfields
rmfield
struct
struct2cell
structfun
如:删除student的id
嵌套结构:
struct(字段1,信息1,字段2,信息2...)
A=struct('data',[3 4 7;8 0 1],'next',struct('testnum','Test 1','xdata',[4 2 8],'ydata',[7 1 6]))
单元数组:
宣告有两种方法:大括号放右边、大括号放左边
读取cell里面的一个值
单元数组函数
cell
cell2mat
cell2struct:将cell转换成structure
celldisp
cellfun
cellplot
cellstr
iscell
mat2cell:把一个数组分成行和列
num2cell
struct2cell
三维数组:
用cat()表示:1是行着拼;2是竖着拼;3是图层拼
reshape():左边变成右边的,条件是r*c=r*c
检查变量状态:
iscell
ischar
isreall
isinterger
islogical
isnumeric
isempty
如果是某种类型的话,则结果为1
文件保存:
file <-> workspace
load()和save()
>> save mydata1.mat
>> load('mydata1.mat')
这种格式保存打开后会乱码
可以用save mydata1.mat -ascii
load('mydata1.mat','-ascii')
文件读取:
xlswrite()
写入文件:
xlswrite()
因为平均数算的时候,是一列一列算的,但是这个表里每个同学分数是一行一行的,那么需要转置一下算mean,然后算完以后在转置一下,就可以把mean的结果放在后面了
括号里面第一位是文件名,第二位是要写入的值,第三位是sheet几,第四位是写入的位置
xlswrite('04score.xlsx',{'mean'},1,'E1')
读取文字部分:
[数字 string]=xlsread('')
fopen(filename,permission),permission是指令
%5.3f是5位数,3位小数点
%c %d %e %f %g %o %s %u %x
读取文件中的数据:
fscanf()
检测文件末尾:
feof()