Matlab 文件读写(I/O)和字符串操作常用命令

本文详细介绍了Matlab中的文件I/O操作,包括fopen、fclose、load、fread、fscanf等,以及字符串操作,如length、strcat、strcmp、strrep等,帮助读者更好地理解和运用这些功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


Import Text Data Files with Low-Level I/O
基本函数:
fscanf: 读写在text or ASCII file中的数据
fgetl: 一次读一行不保留换行符号
fgets: 一次读一行保留换行符号
fread:读二进制文件,与fwrite 对应
fscanf:


A = fscanf(fileID, format) reads and converts  data from a text file into array A  in column order. To convert, fscanf  uses the format and the encoding scheme associated with the file. To set the encodings cheme, use fopen.  The fscanf function reapplies the format throughout the entire file, and positions the file pointer at the end-of-file marker. If fscanf cannot match the format to the data, it reads only the portion that matches into A and stops processing.

A = fscanf(fileID, format, sizeA)  reads sizeA elements into A, and positions the file pointerafter the last element read. sizeA canbe an integer, or can have the form [m,n].

sizeA

example:




Reading Data in a Formatted Pattern
To import text files that importdata and textscan cannotread, consider using fscanf。
fscanf: 自主设计格式。


Reading Data Line-by-Line
MATLAB provides two functions that read lines from filesand store them in string vectors: fgetl and fgets. The fgets function copies the newline characterto the output string, but fgetl does not.
exmaple:


Testing for End of File (EOF)



2014.04.04


Add:
dir(): 查询文件夹中的文件,可加后缀查找指定格式的文件。如 dir(['fk\' , '*.jpg'])表示查找fk文件夹下后缀为‘.jpg’的文件
mkdir():创建文件夹。 mkdir('fj') 在当前目录下创建名为fj文件夹;mkdir('fj\fi')表示当前路径下的fj文件夹里创建fi子文件夹。
rmdir( 'fl'): 用于删除文件夹
copyfile( srcpath , despath): 拷贝文件或者文件夹

一、matlab对路径的操作
1. filesep
返回当前平台目录分隔符,window: '\' ; linux : '/'

2. fullfile
将若干字符串连成完整路径
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值