Data extraction from .csv and .txt files

조회 수: 4 (최근 30일)
Darren Kenney
Darren Kenney 2017년 6월 2일
댓글: dpb 2017년 6월 6일
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!

채택된 답변

dpb
dpb 2017년 6월 3일
"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...
  댓글 수: 2
Darren Kenney
Darren Kenney 2017년 6월 6일
I figured out how to create a loop to extract the data. Sorry for the generic question! I figured it out though.
dpb
dpb 2017년 6월 6일
Glad to hear...

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 EEG/MEG/ECoG에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by