read data from filenames in dir structure with function

2 visualizaciones (últimos 30 días)
I wish to read data from a series of files in a structure called files
files=dir('data*.txt');
I can read the data within a .m file, but when I try to make this a function, including a filepath, I get the following error:
[data1, data2]=read_datafiles(files,PathName));
??? Undefined function or method 'read_datafiles' for input arguments
of type 'struct'.
I tried the structfun variants, but I'm not getting it.

Respuesta aceptada

Nathaniel
Nathaniel el 9 de Jun. de 2012
Is this the first line of read_datafiles.m ?
function [data1 data2] = read_datafiles(files, PathName)
I would guess that it's either not on the path, or doesn't have that line at the beginning.

Más respuestas (2)

Roger Ross
Roger Ross el 9 de Jun. de 2012
which read_datafiles -all echos back the path to the file. Yes, I wrote it. It is a simple routine that reads in data from the data files: open the file, fscan to read the data, close the file, loops through the numel(files). Works fine in the mfile.
Putting this into a function causes the error. I debating on dumping the files structure to a string array, but thought there should be a simple solution.

Roger Ross
Roger Ross el 9 de Jun. de 2012
function [data1,data2]=read_datafiles(files_in,file_path).
Aha, I see. I was changing the directory in the function before it (to check the files) and I did not return. You are correct. thanks.

Categorías

Más información sobre File Operations en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by