Filter löschen
Filter löschen

read data from filenames in dir structure with function

6 Ansichten (letzte 30 Tage)
Roger Ross
Roger Ross am 9 Jun. 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.

Akzeptierte Antwort

Nathaniel
Nathaniel am 9 Jun. 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.

Weitere Antworten (2)

Roger Ross
Roger Ross am 9 Jun. 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 am 9 Jun. 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.

Kategorien

Mehr zu File Operations finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by