how to run a code to several files in a folder?

1 回表示 (過去 30 日間)
Fercho_Sala
Fercho_Sala 2021 年 6 月 1 日
コメント済み: Stephen23 2021 年 6 月 10 日
Hello everyone, how can I run a code for different files in a folder? i.e, Each file is a dataset and the idea is to run the code to generate results independently in a .PDF file in another different folder, thanks.

採用された回答

Jakob B. Nielsen
Jakob B. Nielsen 2021 年 6 月 1 日
編集済み: Jakob B. Nielsen 2021 年 6 月 1 日
You can manage this using for loops, provided that your datafiles are named in an incremental manner. Example, you have 10 files named data1, data2, ... data10.
inputpath='C:\Documents\Example\';
for i=1:10
data=genericreadfunction([inputpath,'data',num2str(i),'.txt']);
%dataanalysis here
reportfunction(['Analysis report no.',num2str(i),'.pdf']);
end
Of course since I have no idea what format your data is in, I cant say which of the numerous generic read functions you should use, nor how you should write your reports, but I hope you get the general idea :)
As an alternative, you can also use
[Name,Path]=uigetfile({'*.txt*'},'Find data...','MultiSelect','on');
for i=1:10
fullpath=fullfile(Path{i},Name{i});
data=genericreadfunction(fullpath);
%data analysis here
end
  1 件のコメント
Fercho_Sala
Fercho_Sala 2021 年 6 月 1 日
@Jakob B. Nielsen the results for each file are separated by ´tabs´, how is possible to put independentely every tab in one sheet inside the resulting .PDF file ? Thank you.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLow-Level File I/O についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by