help-octave
[Top][All Lists]
Advanced

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

Reading files from a directory [was Re: (no subject)]


From: Helios de Rosario
Subject: Reading files from a directory [was Re: (no subject)]
Date: Wed, 24 Jul 2013 10:27:11 +0200

Hi. Sorry for having top-posted, I just noticed it after clicking
"send". I have re-edited the post with Jeff's and my answers in the
correct order now:

>>> On Tue, Jul 23, 2013 at 8:59 PM, Jeff <address@hidden>
wrote:
>>>
>>>>
>>>> I'm running in Linux. Linux usually lets you list files and pass
them
>>>> into programs, or pass the output of one program into another,
etc. Is
>>>> there a way to do that for Octave files, too?
>>>>
>>>> In other words, I want to program it so I can do something like
this
>>>> ls <select-specific-files> | makeGraph.m
>>>> where makeGraph.m would then execute in Octave and process each
file?
>>>> Can I do that in Octave? How?
>>>>
>>>>

>> On Tue, Jul 23, 2013 at 10:19 PM, Dmitri A. Sergatskov <
>> address@hidden> wrote:
>>
>>> Perhaps I misunderstood what you really want, but could you just
use
>>> glob()?
>>> Like :
>>>
>>> fl = glob("*Beta=0195*.csv");
>>> nfiles = rows(fl);
>>>
>>> for ii = 1:nfiles
>>>    u1 = csvread(fl{ii});
>>>    ...etc...
>>> endfor
>>>
>>> Dmitri.
>>> --
>>>


> On Tue, Jul 23, 2013 at 10:32 PM, Jeff <address@hidden>
wrote:
> 
>> Yes, I can just use glob(), but only if I had known about it! :D
(IOW:
>> Thanks).
>> J
>>
>>

>>> El día 24/07/2013 a las 4:42, Jeff <address@hidden>
escribió:
> ... well, with the one catch that I still have to modify my program
each
> run instead of just listing the files and piping them into my
program. But
> still, much easier than the way I was doing it.
> 
> 


If I understand well your question, perhaps you want use cellfun.

For instance, to put the contents of all the csv files in a cell
array:

fl = glob("*Beta=0195*.csv");
csvcontents = cellfun(@csvread, fl, 'UniformOutput', false);

Then, if you have a function "do_things_with_csv" that could be used
with the contents of a single csv file, you can repeat:

cellfun(@do_things_with_csv, csvcontents, 'UniformOutput', false);

Or encapsulate the process of reading the file and the rest of the
process in a single function, and call cellfun only once.

Helios De Rosario

INSTITUTO DE BIOMECÁNICA DE VALENCIA
Universidad Politécnica de Valencia • Edificio 9C
Camino de Vera s/n • 46022 VALENCIA (ESPAÑA)
Tel. +34 96 387 91 60 • Fax +34 96 387 91 69
www.ibv.org

  Antes de imprimir este e-mail piense bien si es necesario hacerlo.
En cumplimiento de la Ley Orgánica 15/1999 reguladora de la Protección
de Datos de Carácter Personal, le informamos de que el presente mensaje
contiene información confidencial, siendo para uso exclusivo del
destinatario arriba indicado. En caso de no ser usted el destinatario
del mismo le informamos que su recepción no le autoriza a su divulgación
o reproducción por cualquier medio, debiendo destruirlo de inmediato,
rogándole lo notifique al remitente.



reply via email to

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