MATLAB(二)变量与档案存取
1.定义string:
eg:s1=‘example’
s2=‘string’
2.串联string:
注意s3=[s1 s2]里有空格,但是结果s3里没有空格。如果要使串联后的s3是一个二维string,[]里需加英文分号,且s1和s2长度需相等。
3.string索引:注意是从1开始而不是C语言里的从0开始。
4.逻辑判断:给出一个逻辑数组,数组里第n个位置上的1代表str里第n个位置上的元素是逻辑判断符号前面的元素。
这里str’s’与’s’str等价
5.将string中某一个元素替换成其他元素:
str(str’s’)=‘Z’
6.结构体的使用,比C简洁:首先上图:
7.定义,eg如下图
查看student(1):
由于student(1)的grade也是一个多维矩阵,查看时要指明grade,查看grade的某一科成绩时,按照索引矩阵的方法,按列索引或者按矩阵行列标号索引。
8.结构体常用的函数:
8.1 获取student(1)里面的所有成员名fieldnames(student(1))
8.2 删除student(1)里面的某一个成员名
8.3 num2cell——Transform a matrix into a cell consistently
8.4 mat2cell——Transform a matrix into a cell variable
- nesting structure结构体嵌套——cell array
(类似于将结构体里的各个元素按照矩阵的方式存储)
如定义下图中的元组,三种方式等价
10.查看cell array其中的一个cell的属性和全部内容:
11.查看cell array其中的一个cell里的某一个位置的内容:
12.Multidimensional Array
13.reshape ()——Returns a new array with assigned rows and columns
eg:
14.
15.文件的保存和下载