Re: read text files



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
.



Relevant Pages

  • Re: Any way to extract B(:,3) from a mat file efficiently?
    ... The function I'm referring to uses a MAT file library that's separate from ... Matlab (e.g. you don't need the shared libraries provided by Matlab). ... Cells of a cell array can be selected using. ... load every other cell of cell array x, ...
    (comp.soft-sys.matlab)
  • "Advanced" load function
    ... I have expanded the functionality of load5 which originally was only ... meant to load matlab R14 files in R13. ... Cells of a cell array can be selected using. ... Partial I/O can be used by using. ...
    (comp.soft-sys.matlab)
  • Re: store part of a cell array on the disk, automatically?
    ... > I'm working with a cell array Cin order to store elements, i.e. ... > At the end of the computation, I load all the values from disk ... load5 test_le C1 ...
    (comp.soft-sys.matlab)
  • Re: use load to load a particular array
    ... Say I have a .mat file 'test.mat' which contains: ... b (10 x 1 cell array) ... I want to load 'a' into my code, but want to be explicit, not just ... programming analyzing the code sees that a is a variable. ...
    (comp.soft-sys.matlab)
  • Re: can the loading of a large number of records go as quick as in DOS
    ... From your posting it seems that the old program only loaded data as it was ... Tekst uit oorspronkelijk bericht weergeven - ... I load the data via Form_load ...
    (microsoft.public.vb.general.discussion)