Loops in sub folders

I have 10 folders and each one has subfolder which has the same name of all 10 called test. under test folders have subfolders named test1 including the data want to plot two rows.

14 件のコメント

Jan
Jan 2018 年 1 月 15 日
Okay. What is your question? I'm not really able to follow your explanations. Do you have 100 subfolders, which contain folders, which contain the actually wanted files?
Star Strider
Star Strider 2018 年 1 月 15 日
The Question:
Hello star, how can I do his command in loop under different folders in different directories.
if true
data = load(strcat('C.....', filePaths(i,:) ,LPCC.dat')); end
Star Strider
Star Strider 2018 年 1 月 15 日
Najiya Omar
Najiya Omar 2018 年 1 月 15 日
10 folders each one has folder named test. Every test folder has folder named test1 including the data.
Jan
Jan 2018 年 1 月 15 日
@Najiya Omar: What exactly is your question?
Jan
Jan 2018 年 1 月 15 日
Since Matlab R2016b the dir command accepts the '/**/' key to search recursively in subfolders.
Najiya Omar
Najiya Omar 2018 年 1 月 15 日
編集済み: Najiya Omar 2018 年 1 月 15 日
I got lost, My question is, I want to generate this order for different folders from 1 to 10, each folder has different subfolders, one of them including my file data, which is (LPCC.mat). so in total I have 10 files of (LPCC.dat), then plot two rows represent x,y for these data in one figure x,y
this the order to skip lines
fidi = fopen('LPCC.dat', 'rt');
D = textscan(fidi, repmat('%f', 1, 13), 'HeaderLines',2, 'CollectOutput',1);
This the loop
myPaths = ['100H' ; '200H' ; '300H' ; '400H' ; '%700H' ; '800H' ; '900H' ; '10000H'];
figure;
hold on;
for i = 1:length(myPaths)
mydata = load(strcat('....', myPaths(i,:) ,'LPCC.dat'));
plot(mydata(:,1),mydata(:,2)));
end
Image Analyst
Image Analyst 2018 年 1 月 15 日
And my demo below didn't work??? Please show how you adapted it.
Najiya Omar
Najiya Omar 2018 年 1 月 16 日
I can't adapt it with my objectivs
Image Analyst
Image Analyst 2018 年 1 月 16 日
Why not??? Just make the obvious changes. Just change the starting path to be whatever top level folder you want, and change the file pattern from . or *.m to *.dat or whatever you want and it should work fine.
Najiya Omar
Najiya Omar 2018 年 1 月 16 日
I got totalNumberOfFiles=0 is that correct!!
Image Analyst
Image Analyst 2018 年 1 月 16 日
I can't debug your adaptation of my code. I have neither the Crystal Ball Toolbox, nor the Mind Reading Toolbox. The only known beta version is only in the hands of Walter Roberson. Until I get a copy, or he answers you, you'll have to post your m-file for us mere mortals.
Najiya Omar
Najiya Omar 2018 年 1 月 16 日
Thanks
Jan
Jan 2018 年 1 月 16 日
This will not work because it pads the char matrix with spaces:
myPaths = ['100H' ; '200H' ; '300H' ; '400H' ; '%700H' ; '800H' ; '900H' ; '10000H'];
Use a cell string instead:
myPaths = {'100H' ; '200H' ; '300H' ; '400H' ; '%700H' ; '800H' ; '900H' ; '10000H'};
and replace myPaths(i,:) by myPaths{i}.

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

回答 (2 件)

Image Analyst
Image Analyst 2018 年 1 月 15 日

0 投票

See attached demos to recursively find files in folders and subfolders.
Najiya Omar
Najiya Omar 2018 年 1 月 16 日

0 投票

this m.file

カテゴリ

ヘルプ センター および File ExchangeFile Operations についてさらに検索

タグ

質問済み:

2018 年 1 月 15 日

コメント済み:

Jan
2018 年 1 月 16 日

Community Treasure Hunt

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

Start Hunting!

Translated by