MATLAB的数据导入与导出.ppt_第1页
MATLAB的数据导入与导出.ppt_第2页
MATLAB的数据导入与导出.ppt_第3页
MATLAB的数据导入与导出.ppt_第4页
MATLAB的数据导入与导出.ppt_第5页
已阅读5页,还剩10页未读 继续免费阅读

下载本文档

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

文档简介

1、MATLAB的数据导入与导出,MATLAB的数据导入,数据的直接输入 A=1 2 3 4 5 6; M文件中生成 利用fopen,fread,和MATLAB输入输出函数。 从ASCII文件中导入 利用load命令,LOAD 接受绝对或相对路径输入。如果文件的扩展名不是.mat,则系统把文件当作ASCII码文件进行处理。 单独使用时,默认输入的命令matlab.mat。如果找不到这个文件,则会报错。 LOAD FILENAME X loads only X. LOAD FILENAME X Y Z . loads just the specified variables. The wildcar

2、d * loads variables that match a pattern (MAT-file only). 如果文件是mat文件,所需变量将在工作空间产生,否则,会产生一个双精度矩阵,矩阵名为文件名。 S = LOAD(.) returns the contents of FILENAME in variable S. If FILENAME is a MAT file, S is a struct containing fields matching the variables retrieved. If FILENAME is an ASCII file, S is a doubl

3、e precision array.,举例,load fname a* % Load variables starting with a load fname -regexp bd3$ % Load variables starting with b and % followed by 3 digits load fname -regexp d % Load variables containing any digits,利用特定文件读取函数 dlmread wk1read textscan textread 创建mex文件读取文件 创建其他程序文件读取,MATLAB的数据导出,diary s

4、ave ascii 以特定格式写入文件 利用特定文件写入程序 dlmwrite 作为mat文件输出数据,MATLAB的文件操作,UIGETFILE 对话框打开文件方式. FILENAME, PATHNAME, FILTERINDEX = UIGETFILE(FILTERSPEC, TITLE) 显示一个需要用户完成的对话框,返回文件名,文件路径,和是否打开成功,如果打开成功,返回成功标志,否则会出现一错误信息,用户可以打开另一文件,或取消。 filename, pathname, filterindex = uigetfile(*.m, Pick an M-file);,MATLAB的文件操作

5、,UIPUTFILE 对话框打开文件方式. FILENAME, PATHNAME, FILTERINDEX = UIPUTFILE(FILTERSPEC, TITLE) 显示一个需要用户完成的对话框,返回文件名,文件路径,和是否打开成功,如果打开成功,返回成功标志,否则会出现一错误信息,用户可以打开另一文件,或取消。 filename, pathname = uiputfile(matlab.mat, Save Workspace as);,MATLAB的文件操作,FOPEN 打开文件 FILENAME 可以是一个相对路径,如果文件不在当前目录,系统将会在其他路径进行搜索。 FID = FOP

6、EN(FILENAME,PERMISSION) FID 称为文件标识符,如果错误,返回-1,MATLAB的文件操作,r read w write (create if necessary) a append (create if necessary) r+ read and write (do not create) w+ truncate or create for read and write a+ read and append (create if necessary) W write without automatic flushing A append without automa

7、tic flushing,MATLAB的文件操作,Two file identifiers are automatically available and need not be opened. They are FID=1 (standard output) and FID=2 (standard error). FID, MESSAGE = FOPEN(FILENAME,PERMISSION) returns a system dependent error message if the open is not successful.,MATLAB的文件操作,FCLOSE Close fi

8、le. ST = FCLOSE(FID) closes the file with file identifier FID, which is an integer obtained from an earlier FOPEN. FCLOSE returns 0 if successful and -1 if not. ST = FCLOSE(a) closes all open files, except 0, 1 and 2.,MATLAB的文件操作,FGETS Read line from file, keep newline character. TLINE = FGETS(FID)

9、returns the next line of a file associated with file identifier FID as a MATLAB string. The line terminator is included. Use FGETL to get the next line WITHOUT the line terminator. If just an end-of-file is encountered then -1 is returned.,MATLAB的文件操作,FPRINTF Write formatted data to file. COUNT = FP

10、RINTF(FID,FORMAT,A,.) formats the data in the real part of array A (and in any additional array arguments), under control of the specified FORMAT string, and writes it to the file associated with file identifier FID. COUNT is the number of bytes successfully written. FID is an integer file identifier obtained from FOPEN. It can also be 1 for standard output (the screen) or 2 for standard error. If FID is omitted

温馨提示

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

评论

0/150

提交评论