四、Matlab 之 常见函数的使用

网友投稿 822 2022-05-30

1、数据处理:

保存数据到本地并加载数据到matlab方法

① mat格式的读取

保存

clear; a = magic(3); save myfata1.mat %save mydata2.mat -ascii %这个可以用记事本打开

1

2

四、Matlab 之 常见函数的使用

3

4

加载

clear; load('mydata1.mat'); load('mydata2.mat','-ascii');

1

2

3

② excel格式的读写

读取

Score = xlsread('1.xlsx','B2:D4') %自己会滤除文字

1

2

写入

M = mean(mean')'; xlswrite('1.xlsx', M, 1, 'E2:E4'); %格式为 xlswrite(filename, variable, sheet, location); xlswrite('1.xlsx', {'Mean'}, 1, 'E1');

1

2

3

4

如何excel的文字呢?它会自动滤除文字的。

[Score, Text] = xlsread('1.xlsx');

1

同样,,,写回去再使用

xlswrite('1.xlsx', headers, 1, 'A1:D4'); xlswrite('1.xlsx', score, 1, 'B2:D4');

1

2

即可。。。

2、关于上面的mean函数

mean是求平均数,但是注意是以列向量求的。

如果想求行向量的平均数,需要先把发转置然后再求。

3、文件操作(跟C语言大同小异,复习下。。。)

x = 0:pi/10:pi; y = sin(x); fid = fopen('sin.txt', 'w'); for i=1:11 fprintf(fid, '%5.3f %8.4f\n', x(i), y(i)); end fclose(fid); type sin.txt %查看这个txt文档的内容

1

2

3

4

5

6

7

8

关于读取,也再上个例程!

fid = fopen('1.text', 'r'); i = 1; while ~feof(fid) name(1,:) = fscanf(fid, '%5c', 1); year(i) = fscanf(fid, '%d', 1); No(i) = fscanf(fid, '%d\n', 1); ......

1

2

3

4

5

6

7

4、reshape函数

按照顺序将原来单元数组的元素进行重新放置,得到新的单元数组元素个数和原数组相同。

必须满足R1C1 = R2C2

题目:

查找字符串中给定字符的位置和数目

function test() str = input('str = '); c = input('c = '); index = strfind(str, c); disp(index); disp(length(index));

1

2

3

4

5

6

输入字符的首字母大写,其他小写

function test() str = input('str = '); n = length(str); if (str(1)>'Z') str(1) = str(1) - 32; end for i=2:n if(str(i) < 'a') str(i) = str(i) + 32; end end disp(str);

1

2

3

4

5

6

7

8

9

10

11

12

MATLAB 数据结构

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:C#编程-121:文件保存之SaveFileDialog控件
下一篇:【ESP8266之LUA开发】六、建立TCP客户端,实现ADC测量,单点接地的小知识
相关文章