Im using a software to run an analysis with a variable (in this case 12 different several wind speeds). I have a main folder with a subfolder for each wind speed with alot of files. However I am only interested in reading the results.tda file in each subfolder (they all have the same name). I have managed to read all the subfolders, creating the D_sub which gives a 1×12 struct with each file and corresponding folder as seen in the image below. In this example Ive used the txt file for testing but I also want to use the results.tda files.
However, I am only able to get the last result.txt file in the workspace.
I am currently using the following code to go through the folders and find the files, but "content" only gives me the data for the last run (Wind_9).
Goal: to get e.g. result1 for Wind1, result5 for Wind5 etc etc and to be able to extract the data I want from each result file.
Main = 'C:MainFolder';Sub = dir(fullfile(Main,'*'));Sub = Sub(3:end); % Eliminate "." and ".."
N = setdiff({Sub([Sub.isdir]).name},{'.','..'}); % list of subfolders of Main.
for i = 1 : numel(N) D_sub(i) = dir( fullfile( Main, Sub(i).name, 'results.txt' )) ; nel = {D_sub(~[D_sub.isdir]).name}; for j = 1 : numel(nel) inLocator = fullfile( Main, Sub(i).name, D_sub(j).name ) ; content = fileread( inLocator ) ; end end
Thanks!
Best Answer