double() Convert to double precision
single() Convert to single precision
int8() Convert to 8-bit signed integer
int16() Convert to 16-bit signed integer
int32() Convert to 32-bit signed integer
int64() Convert to 64-bit signed integer
uint8() Convert to 8-bit unsigned integer
uint16() Convert to 16-bit unsigned integer
uint32() Convert to 32-bit unsigned integer
uint64() Convert to 64-bit unsigned integer
Character (char)
s1 = 'h'
whos
uint16(s1)
>> student(2).name = 'Ann Lane';
student(2).id = 'aln4@sfu.ca';
student(2).number = 301078853;
student(2).grade = [95 100 90; 95 82 97; 100 85 100];
>> student(2)
ans =
包含以下字段的 struct:
name: 'Ann Lane'
id: 'aln4@sfu.ca'
number: 301078853
grade: [3×3 double]
>> student(2).grade(7)
ans =
90
先回传为字符,再进行删除操作:
>> A = struct('data', [3 4 7; 8 0 1], 'nest', struct('testnum', 'Test 1', 'xdata', [4 2 8],'ydata', [7 1 6]));
>> A(2).data = [9 3 2; 7 6 5];
A(2).nest.testnum = 'Test 2';
A(2).nest.xdata = [3 4 2];
A(2).nest.ydata = [5 0 9];
A.nest
ans =
包含以下字段的 struct:
testnum: 'Test 1'
xdata: [4 2 8]
ydata: [7 1 6]
ans =
包含以下字段的 struct:
testnum: 'Test 2'
xdata: [3 4 2]
ydata: [5 0 9]
单元格数组中的每个条目都包含一个指向数据结构的指针
同一单元格数组的不同单元格可以指向不同类型的数据结构
补充: A{1,1}(1,1)也可以定位到元素1
(行,列)
双引号才能创建字符串矩阵:
>> a = magic(3)
a =
8 1 6
3 5 7
4 9 2
>> b = num2cell(a)
b =
3×3 cell 数组
{[8]} {[1]} {[6]}
{[3]} {[5]} {[7]}
{[4]} {[9]} {[2]}
>> c = mat2cell(a, [1 1 1], 3)
c =
3×1 cell 数组
{1×3 double}
{1×3 double}
{1×3 double}
三个维度:
Excel File Reading: xlsread()
Excel File Writing: xlswrite()
Calculate the standard deviations and write them into column F
>> M = mean(Score')';
xlswrite('04Score.xlsx', M, 1, 'E2:E4');
xlswrite('04Score.xlsx', {'standard deviations'}, 1, 'E1');
获取文本和数字:[Score Header] = xlsread('04Score.xlsx')
>> x = 0:pi/10:pi; y = sin(x); fid = fopen('sinx.txt','w');
for i=1:11
fprintf(fid,'%5.3f %8.4f\n', x(i), y(i));
//总共5个数值,有三个小数
//总共8个数值,有四个小数且换行
end
fclose(fid); type sinx.txt
0.000 0.0000
0.314 0.3090
0.628 0.5878
0.942 0.8090
1.257 0.9511
1.571 1.0000
1.885 0.9511
2.199 0.8090
2.513 0.5878
2.827 0.3090
3.142 0.0000