Sunday, March 30, 2008

使用matlab批量读取文件

每次用的时候都要重新查,诶,干脆存个档。

From matlab help:

files = dir('directory') returns the list of files in the specified directory (or the current directory, if dirname is not specified) to an m-by-1 structure with the fields:
name: Filename
date: Modification date
bytes: Number of bytes allocated to the file
isdir: 1 if name is a directory; 0 if not

e.g. To view the M-files in the MATLAB audio directory, type dir(fullfile(matlabroot,'toolbox/matlab/audio/*.m'))

另外注意:
The following examples both produce the same result on UNIX, but only the second one works on all platforms.
fullfile(matlabroot,'toolbox/matlab/general/Contents.m') fullfile(matlabroot,'toolbox','matlab','general','Contents.m') %都用这个就好啦

所以要读当前目录下所有jpg图像文件的话 files = dir(fullfile(pwd,'*.jpg'))就行了。

No comments :