matlab3

198 阅读1分钟

variable默认类型是double

s1 = 'Example';
s2 = 'string';
% [s1 s2] = 'Examplestring'
% [s1;s2]报错,因为字符串长度不一样
str = 'aardvark'

>> 'a' == str
ans =
1 1 0 0 0 1 0 0

>> str(str == 'a') = 'Z'
str = 
'ZZrdvZrk'

structure

fieldnames(students) 显示students的所有成员名称

rmfield(students,'id') 删除students结构体中成员id

cell

A(1,1) = {[1 4 3; 0 5 8; 7 2 9]}; 等价于 A{1,1} = [1 4 3;0 5 8; 7 2 9];

A(1,2) = {'Anne Smith'}; 等价于 A{1,2} = 'Anne Smith';

A(2,1) = {3+7i}; 等价于 A{2,1} = 3+7i;

A(2,2) = {-pi:pi:pi}; 等价于 A{2,2} = -pi:pi:pi;

cat指令:

A = [1 2; 3 4] B = [5 6; 7 8]

cat(1, A, B) = [1 2;3 4;5 6;7 8]

cat(2, A, B) = [1 2 5 6;3 4 7 8]

cat(3, A, B) 层拼接,生成一个222的三维元胞(cell)

reshape指令:

A = [1:3; 4:6]

B = reshape(A,3,2) 则B = [1 5; 4 3; 2 6]

文件操作

save mydata1.mat 保存所有变量

save mydata1.mat -ascii