フィルターのクリア

read data from filenames in dir structure with function

6 ビュー (過去 30 日間)
Roger Ross
Roger Ross 2012 年 6 月 9 日
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 Center および File ExchangeFile Operations についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by