We are new to Matlab and we would need help with the following problem: We have 100 .mat files in a folder consisting of a matrix with several column vector variables. The aim is to have an automated process which reads in all the files and performs certain calculations on all of them. In more detail it should do the following: A specific function file (already existing) is called to perform a calculation on each file and should then somehow record the value (probably store the values in a new vector?!) of one of the function outcome variables as we need to do further calculations on them. We would need to calculate the mean of these values. Can anybody show us how a script for our problem would look like? We read something about Batch-programs and loops, but we are not sure how exactly to solve the problem. Can it be done with either of those (batch vs. loop) or do we need to combine both? So would a loop allow me to read in multiple files and perform a function on each one? If so, how do we have to write such a loop? And there is another problem: For the function file to work, certain function input variables need to be predefined in the M-file. Do we have to define them within the loop? And for the Batch version we already created one file with all files included. Here a shortened version of it:
We furthermore used these commands for the main M-File to “connect” it to the other Batch-file, but it somehow doesn’t work:
%% Set path cd ('N:\backups\Folder5\HR data analysis')
thePath.data = fullfile(pwd,'subject data','PTSDdata','to be added'); thePath.programs = fullfile(pwd,'programs');
%% Select any Out4 file and open it cd (thePath.data)
If using the Batch solution for our problem, how could we connect the files with one another?
Any kind of help would be highly appreciated. Thank you!
No products are associated with this question.
You could try something like
struct_array_of_matfiles = transpose( dir( 'folder_in_question\*.mat' ) ); for sa = struct_array_of_matfiles struct_of_data = load( fullfile( folder_in_question, sa.name ) ); end
What do you mean by "connect the files with one another" ?
Play games and win prizes!Learn more