matlab中的数据读取_第1页
matlab中的数据读取_第2页
matlab中的数据读取_第3页
matlab中的数据读取_第4页
matlab中的数据读取_第5页
已阅读5页,还剩20页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、 数据读取1一 、将excel数据导入matlab1.直接导入在文件菜单中选择 data,按照提示进行操作至结束。(book1.xls) Sheet1Sheet1 = 1 2 3 4 5 622.xlsread函数导入, pathname=uigetfile(*.xls); %寻找源文件file=pathname ; %赋名x=xlsread(file); %格式转换为矩阵 运行上面命令后,出现select open 对话框34选择如下的excel文件5 xx = 1 2 3 4 5 66其他格式:num = xlsread()num = xlsread(, -1)num = xlsread(

2、, sheet)num = xlsread(, range)num = xlsread(, sheet, range)num = xlsread(, sheet, range, basic)num = xlsread(, ., functionhandle)num, txt= xlsread(, .)num, txt, raw = xlsread(, .)num, txt, raw, X = xlsread(, ., functionhandle)7 A = xlsread(book1.xls, 1, E11:E12)A = 1 48二、将matlab数据写入excelxlswrite(, M

3、)将矩阵M写入, M的行数不能超过65536 M的列数不能超过256 在的sheet1中,从A1开始写入。 a=magic(5); xlswrite(book2.xls,a) 9其他格式xlswrite(, M, sheet)xlswrite(, M, range)xlswrite(, M, sheet, range)status = xlswrite(, .)status, message = xlswrite(, .) xlswrite(book3, a, shumo, E1)将矩阵a写入book3.xls的shumo工作簿,从E1开始写入。10D = xlsread(Btest.xls,

4、 1, B2:F5001); xlswrite(book4.xls,D)11三、 将txt文件数据导入 matlabtest1.txt 的文件内容如下你好,我的数据欢迎来到动力学与控制技术论坛1 11 111 11112 22 222 22223 33 333 33334 44 444 44445 55 555 555512方法在文件菜单中选择 data,按照提示进行操作至结束。 datadata =1 11 111 11112 22 222 22223 33 333 33334 44 444 44445 55 555 555513 textdatatextdata = 你好 欢迎来到 动力学

5、与控制技术论坛 14文件test2.txt内容: 你好1 11 111 1111欢迎来到2 22 222 2222动力学与仿真控制论坛3 33 333 33334 44 444 44445 55 555 5555 说明:这种内容格式的文件用上面的方法是不行的。15方法: fidin=fopen(test2.txt); % 打开test2.txt文件 fidout=fopen(mkmatlab.txt,w); % 创建MKMATLAB.txt文件while feof(fidin) % 判断是否为文件末尾 tline=fgetl(fidin); % 从文件读行 if double(tline(1)

6、=48&double(tline(1) MKMK = 1 11 111 1111 2 22 222 2222 3 33 333 3333 4 44 444 4444 5 55 555 555517四、将matlab数据写入txt文件dlmwrite(, M)dlmwrite(, M, D)dlmwrite(, M, D, R, C)dlmwrite(, M, attrib1, value1, attrib2, value2, .)dlmwrite(, M, -append)dlmwrite(, M, -append, attribute-value list)18 a=magic(5); dl

7、mwrite(test3.txt,a) !type test3.txt 17,24,1,8,1523,5,7,14,164,6,13,20,2210,12,19,21,311,18,25,2,919 dlmwrite(test4.txt,a,delimiter, ) !type test4.txt17241815235714164 61320221012192131118252920 M = magic(3); dlmwrite(test5.txt, M*5 M/5, ) !type test5.txt40 5 30 1.6 0.2 1.215 25 35 0.6 1 1.420 45 10

8、0.8 1.8 0.421 dlmwrite(test5.txt, rand(3), .-append, roffset, 1, delimiter, ) !type test5.txt40 5 30 1.6 0.2 1.215 25 35 0.6 1 1.420 45 10 0.8 1.8 0.4 0.81472 0.91338 0.27850.90579 0.63236 0.546880.12699 0.09754 0.9575122 dlmread(test5.txt)ans = 40.0000 5.0000 30.0000 1.6000 0.2000 1.2000 15.0000 25.0000 35.0000 0.6000 1.0000 1.4000 20.0000 45.0000 10.0000 0.8000 1.8000 0.4000 0.8147 0.9134 0.2785 0 0 0 0.9058 0.6324 0.5469 0 0 0 0.1270 0.0975 0.9575 0 0 023四、matlab数据文件1.可以将工作空间中

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论