Apply code on matlab files in different directories ?

3 ビュー (過去 30 日間)
geoabidali
geoabidali 2015 年 8 月 18 日
コメント済み: geoabidali 2015 年 8 月 19 日
I want to apply the code on the .m files present in sub directories. The names of sub-directories started from 001 up to 365 in sequence. Could someone help me to write some code ? I have a very basic knowledge of Matlab scripts.
Thanks in advance!
  2 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2015 年 8 月 18 日
What code?
geoabidali
geoabidali 2015 年 8 月 18 日
The attached code i want to apply on all the files present in the sub-directories.

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

回答 (2 件)

Walter Roberson
Walter Roberson 2015 年 8 月 18 日

David Sanchez
David Sanchez 2015 年 8 月 18 日
From Documentation:
path(path,'newpath') adds the newpath folder to the end of the search path. If newpath is already on the search path, then path(path,'newpath') moves newpath to the end of the search path.
In your case, you should do something like this:
your_path = path where you have your sub-directories;
for k=1:365 % sub-directories started from 001 up to 365 in sequence
str = strcat(your_path,'\000); % add the temporary 000 ending
file_number = num2str(k); % convert index to string
L = length(str); % length of your path
LK = length(file_number); % length of index as string
new_path = strcat(str(1:L-LK),file_number); % full new path od kth folder
path(path,new_path) % add the kth folder to matlab path
end
  11 件のコメント
Walter Roberson
Walter Roberson 2015 年 8 月 19 日
You seem to be working with 365 different subdirectories, but I cannot tell which file or files you want to use out of each subdirectory. Is there a data_hr.mat file in each subdirectory that has a single variable in it? Is there a data_hr.csv file in each subdirectory? Is data_hr the name of a column in a .xls file that has a consistent name in each subdirectory? Is there a data_hr.m file in each subdirectory that is a function that returns data? Are there multiple files in each sub-directory that each need to be processed?
geoabidali
geoabidali 2015 年 8 月 19 日
I have the files like A00100ADO_E.mat, A00100ADO_N.mat in all the sub-directories and all of them have single variable which is 'data_hr' in each file.

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

カテゴリ

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