Navigating and extracting data from different folders
Afficher commentaires plus anciens
Hello,
I have a path of data which I would like to access various folders and various files within these folders. All the folders with the data I require to access are stored within the single folder ''Experimental data''.
Within the single folder, ''experimental data'' there is a number of participant folders labelled as follows:

Each H** folder which is the particpant number contains three seperate folders from different measurement devices. Namely research sensor, motionsense and vicon. For example if one were to open H01, three folders would be stored within it:

Within these three folders associated to each particiapnt there are a number of files which contain data of different activities carried out by the individual. For example the different tasks which are contained in the three files (for example if Vicon folder were opened) are listed as follows:

All tasks in each of the three folders vicon, motionsense and researchdevice are labelled in the same format. Each of the three folders contain the same files, with the same activities however, the data has just been collected from the specific device.
I would like to be able to compare each individual task file, T01 for instance for all H**files (the different participants) for each of the three measuremnet devices which have their data stored in the three seperate files (vicon, motionsense and research device).
In other words I would like to be able to read in the data for a specific task (specified by user) for all three measuremnet systems (vicon, motionsense and research device) for all participants (All H** folders).
I was able to access data for each participant seperately but I am unsure how to collate all the tasks to be able to compare the same task but carried out by different particpants.
Any help is hugely appreciated.
Please let me know if any clarity needs to be provided, or if existing code would be helpful?
Thanks again,
Lexi
4 commentaires
Hello,
MyFolder = 'Path_to_your_folder'
MyFolderInfo = dir(strcat(MyFolder,'\**\*'))
This will give you a structure containing informations on all the files and folder inside "MyFolder".
You should then be able to discriminate your data using conditions on the folder paths and/or file name and load the data you are looking for. For example:
userinput = 'T01.xls'; %input file name
%find all file name with userinput
condition = regexp({MyFolderInfo.name},userinput);
%create a logical mask and find the indices of valid data
index_mask = find(cellfun(@(x)~isempty(x),condition));
%load selected data in a working structure
data_name = regexprep(userinput,'\.\w+'); %take user input and remove all character after a .
for i_selected = 1:length(index_mask)
%create a structure reference
structured_data(i_selected).(data_name) = load(fullfile(MyFolderInfo(index_mask(i_selected)).folder,MyFolderInfo(index_mask(i_selected)).name))
end
userinput = 'MotionSense'; %input file name
%find all folder name with userinput
condition = regexp({MyFolderInfo.folder},userinput);
%repeat indexing and loading step
Using a similar logic, you should be able to select a given participant, a given task, a given measurement device and compare the data.
Hope this helps
alexandra ligeti
le 13 Mai 2022
alexandra ligeti
le 13 Mai 2022
1 * : matches any number of characters.
2 * : matches any number of subdirectories.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Workspace Variables and MAT Files dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!