read data from filenames in dir structure with function

7 vues (au cours des 30 derniers jours)
Roger Ross
Roger Ross le 9 Juin 2012
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.

Réponse acceptée

Nathaniel
Nathaniel le 9 Juin 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.

Plus de réponses (2)

Roger Ross
Roger Ross le 9 Juin 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 le 9 Juin 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.

Catégories

En savoir plus sur File Operations dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by