MATLAB: Read data from filenames in dir structure with function

dirfunctionMATLABstructures

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.

Best Answer

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.