matlab file open,matlab学习之文件操作

操作命令:

>>[pathstr,name,ext,versn]

= fileparts(file)

%获取文件路径的各种信息

例如:

[pathstr,name,ext,versn] =

fileparts('D:\winxp-old\课件-教程\课件\matlab教学\matlab宝典源代码\Ch13\13.4.2\Compli_ball.m')

pathstr =

D:\winxp-old\课件-教程\课件\matlab教学\matlab宝典源代码\Ch13\13.4.2

name =

Compli_ball

ext =

.m

versn =

''

>>[fid,message] =

fopen('file','permission')

%打开文件

'r' Open file for reading (default).读文件

'w' Open file, or create new file, for writing; discard existing

contents, if any.

打开文件,创建新文件;将原有的内容去掉。

'a' Open file, or create new file, for writing; append data to

the end of the file.

打开文件,创建新文件;原有的内容之后添加数据。

'r+' Open file for reading and writing.读写文件

'w+' Open file, or create new file, for reading and writing;

discard existing contents, if any.

读写文件,创建新文件;将原有的内容去掉。

'a+' Open file, or create new file, for reading and writing;

append data to the end of the file.打开文件,创建新文件;原有的内容之后添加数据。

'A' Append without automatic flushing; used with tape

drives.非自动冲洗添加

'W' Write without automatic flushing; used with tape

drives.非自动冲洗写。

删除文件

>>status =

fclose(fid);

%删除文件,必须要关闭句柄

>>delete

file;

读取文件

>>data =

fread(fid);

%得到数值数组

>>disp(char(data'))

%显示字符串

写入二进制文件

>>fwrite(fid,inputdata,mode)

%fid是文件句柄 inputdata输入的数据

处理文本文件

>>M =

csvread(filename, row, col, range)

%Read comma-separated value file 读取逗号分割的文件

Specify range using the notation [R1 C1 R2 C2] where (R1,C1) is

the upper left corner of the data to be read and (R2,C2) is the

lower right corner.

>>M =

dlmread(filename, delimiter)

%可以设置数据分隔符

>>fgetl

%Read line from file, discarding newline

character每次读一行,去掉新行符

>>fgets

%Read line from file, keeping newline

character每次读一行,不去掉新行符

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值