Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have one directory with many folders. Each folder contains a .txt file (eg, file1 contain number1.txt, file2 contain number2.txt etc). these files has 4 columns with double numbers.

Also I have, outside of this directories one matlab code that reads the .txt file, makes calculations and write a file with the results.

Is there a way to run tha matlab code for all the folders with automated manner? I mean to run the code with an easy way, and not running the matlab code one by one for each folder?

What I have tried:

I found this but no use:
addpath('mycode.m')
dirContent=dir(); % get content of current directory
dirContent(~[dirContent.isdir])=[]; % delete entries that are no folders
dirContent(1:2)=[]; % delete '.' and '..' directory
folders={dirContent.name} % get folder names
for dirNr=1:numel(folders)
    cd(folders{dirNr}); % change dir to specified folder
    mycode();
    cd ..; % go back up a level
end
Posted
Updated 22-Apr-21 22:28pm
v2
Comments
Richard MacCutchan 23-Apr-21 5:15am    
You just need to modify that code to find all the files in each subdirectory that you are interested in, and process their content in the program one by one.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900