Re: read text files
- From: roberson@xxxxxxxxxxxxxxxxxx (Walter Roberson)
- Date: Wed, 30 Jul 2008 21:53:04 +0000 (UTC)
In article <g6qn43$fva$1@xxxxxxxxxxxxxxxxxx>,
samik bhattacharya <nit.samik@xxxxxxxxx> wrote:
i am having a folder which contains txt files named
p1_1.txt,p1_2.txt,........,p1_24.txt. i need to read the
file in order , i.e starting from p1_1 ,p1_2 to p1_24. to
avoid using load command so many times i used
f_list= dir('*.txt) and then fileparts(f_list(i).name) in
a loop. but problem is the f_list.name are arranged like
p10_0,p10_1,p10_10. i understand the order in which the
structure stores the name. but is there any other tricky
way to read the files in order without using load several
times?
No, there is no way in matlab to load() several files simultaneously.
If you want to read the files in a different order, then
myorder = sortfilenames({f_list.name});
for i = myorder
load(f_list(i).name);
%now do whatever
end
where sortfilenames is a routine that you write that takes
a cell array of strings as input and returns the sort indices according
to whatever strange or wonderful rules you may care to invent.
I would question, though, why it is important to load the text files
in exactly that particular order. If the text files will all fit in
memory, just load them in any order, saving the loaded data into a cell
array; then after they are all loaded, process the cell array in whatever
order(s) you want.
--
"After all, what problems has intellectualism ever solved?"
-- Robert Gilman
.
- References:
- read text files
- From: samik bhattacharya
- read text files
- Prev by Date: strings
- Next by Date: Multiple Line Diplays
- Previous by thread: read text files
- Next by thread: Re: read text files
- Index(es):
Relevant Pages
|