Reading many files in one loop

How can I read file names and convert them to a matrix? I have more than one file and I want to read their contents in one loop of the program. Thanks

3 个评论

What is your current code? I assume you must have tried something yourself. Which errors are you getting?
It is not useful to convert filenames to a matrix. Do you want to import the file's contents into a matrix?
no I need to read the contents of a specific folder's file names (as text), then run selection rule to pick names only that i want.
The problem is that files being send to a folder, with names of the format (yyyymmddhh.jpg) so each day there is a marked file as (yymmddT.jpg)... (T for terminate). The names are varying, i can't read all by fopen commands, i can't specify the required name unless they are in some form.

请先登录,再进行评论。

 采纳的回答

更多回答(2 个)

doc dir
D = dir([myfolder 'my*file*name*.*']);
files = {D.name}';

2 个评论

how to use files? I used it like
D = dir(['C:\Documents and Settings\John\My Documents\MATLAB\Pic_Down' '*.jpg'])
files = {D.name}';
files =
{}
any ideas?
This means, that no file matchs the filter:
'C:\Documents and Settings\John\My Documents\MATLAB\Pic_Down*.jpg'
Perhaps you want:
'C:\Documents and Settings\John\My Documents\MATLAB\Pic_Down\*.jpg'
Note: fullfile() is much better for constructing file names than STRCAT, HORZCAT or [.].

请先登录,再进行评论。

Jan
Jan 2013-4-4

0 个投票

It is always a good idea to read the FAQ, because it is efficient to profit from the errors of others.

类别

在 帮助中心 和 File Exchange 中查找有关 File Operations 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by