フィルターのクリア

Passing a .txt file as a function parameter

13 ビュー (過去 30 日間)
Arielle
Arielle 2013 年 4 月 22 日
I already have several .txt files in my working directory that I would like to search in order to obtain certain information included in them.
My question is:
Can I create a function in which I can pass these .txt files as parameters (and handle the data collection within this function)? And if so, given that the .txt files are in the working directory, how can I appropriately pass them to this function?
Thanks, Arielle

採用された回答

Cedric
Cedric 2013 年 4 月 22 日
編集済み: Cedric 2013 年 4 月 22 日
You should pass file names to the function and/or a base path.
filenames = {'a.txt', 'b.txt'} ; % Cell array of file names.
results = myFunction(filenames) ;
with myFunction.m as follows :
function results = myFunction(filenames)
for k = 1 : length(filenames)
name = filenames{k} ;
% .. do something, e.g. FOPEN + read, CSVREAD, DLMREAD
% and define results.
end
end
  1 件のコメント
Arielle
Arielle 2013 年 4 月 22 日
Perfect. Thank you.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSearch Path についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by