read data from filenames in dir structure with function

6 次查看(过去 30 天)
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.

采纳的回答

Nathaniel
Nathaniel 2012-6-9
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.

更多回答(2 个)

Roger Ross
Roger Ross 2012-6-9
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 2012-6-9
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.

类别

Help CenterFile Exchange 中查找有关 File Operations 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by