MATLAB: Data extraction from .csv and .txt files

csvdata extractiontxt

I have an EEG database with 101 subjects. I have written a script that will automatically point me to the correct raw data files for each subject (there are EEG, Eyetracking, and Behavioural files for each subject) but I need to create some sort of loop so I can cycle through the database and extract data from each file for each subject.
I created a subject database that includes subject ID, and other demographic info about that subject. In addition, I have included columns that have filename information such as "age_range" and "file_prefix" which I will need matlab to reference in order to open the correct file. For each subject, their EEG file has a slightly different prefix but I have recorded all of this in the subject database as "file_prefx" already. All I need to do is point MATLAB to the correct column so it will automatically fill in the correct file name and open the correct file.
I'm only creating a for loop for the subjects so I can open the correct file in the first place right now. Once I've finished that, I will need to use some sort of function that extracts the data I'm interested in and formats it into a table.
The subject database is a .csv file and I have opened it using the function
a=fopen('filename.csv');
b=textscan(a, '%s %s %s %s %s %s %s %s %s', 'delimiter', ',');
Can anyone help me with creating this for loop? I'm new to matlab so I need some help. I've checked the documentation but I'm not quite sure how to open individual files based on a row of the subject database.
Thanks in advance!

Best Answer

"I'm not quite sure how to open individual files based on a row of the subject database"
Well, it's not the row of the database you need, it's to use the data for the given row to build the actual filename from the component pieces-parts and use that in the appropriate input function.
What you've described sounds like you've got the right information stored, unfortunately your description is so generic it's not possible to actually write any specific code using that description. Show us a short (a line or two with the appropriate variable names) of how you actually have constructed the database and it'll be simple enough to string those components together properly.
I might note that if your files have a consistent naming pattern, it might be possible to use wild cards and dir to simply scan the directory and retrieve the specific files...
Related Question