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
将若干字符串连成完整路径