help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Loading data from file and omitting some extensions


From: Andy Buckle
Subject: Re: Loading data from file and omitting some extensions
Date: Wed, 22 Jan 2014 11:01:15 +0000




On 22 January 2014 10:46, st.michal88 <address@hidden> wrote:
Hello everybody,

 I am loading data from files and and puting it into matrices for further
calculations. My function works on multiple files and loads all the files
from directory. The  problems starts when in the same directory there are
some files with a different extension than .txt. Could you help me how to
make a statement excluding files ending with something else than .txt.?

This is the way I load the data:

 nr = readdir (pwd)
 i=rows(nr);

 for a=(1:i)
   if (isdir(nr(a))==0)
     data = "" (nr(a), "r");
     A=dlmread(data,'',0,0);
     fclose(data);

  ...calculations...

 endfor

ooops. I forgot to reply all. Also correcting a typo.

use dir with a glob, instead of readdir

nr=dir('*.txt');

note that you get a struct array back with more than just names (what readdir does).

so nr(1).name gets you the name of the first text file.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]