Loop for storing files from sub-folders in new variables?

조회 수: 1 (최근 30일)
JM
JM 2018년 10월 24일
댓글: Image Analyst 2018년 10월 30일
I have 10 folders, 1 for each of my participants. Each folder has 3 files per each trial, so trial 1 will have an A file, B file, and C file that represent different hardware collecting data. and they all follow the same naming convention (Afile1,Afile2,Afile3,etc).
I'm trying to create a loop that runs through Folder 1, Folder 2, etc and extracts each of those files for each trial and puts them in a variable.
My goal is to have a variable for A files, B files, and C files that is organized for participants 1-10. The layout would look something like this
AFiles = 24 rows (24 trials per participant) 10 columns (10 participants).
Hope this makes sense. I've tried numerous codes that I've found from searching on how to handle sub-folders, importing multiple folders, etc but none seem to work.

답변 (1개)

Image Analyst
Image Analyst 2018년 10월 24일
Possibly the easiest is to use the fileDataStore() function.
Alternatively, use dir() with the double asterisk option. (Demo attached).
  댓글 수: 2
JM
JM 2018년 10월 29일
편집: JM 2018년 10월 29일
Hey Image Analyst,
Thanks for the response. I read through the document and was able to utilize that code and adapt it for my needs.
However, the main problem I am encountering is still storing the data itself as a variable. The code you provided processes those files, but then when I try and store one of the .txt files as a variable, I am getting error messages.
The main thing I was looking for was a loop that takes in all of the files I have now processed, and save all of the data from the ones with the same name as a variable if that makes sense.
Thank you
Image Analyst
Image Analyst 2018년 10월 30일
Well, it's kind of vague. Why can't you just process the file inside the loop? Why do you need to store them all for use later, outside the loop? If you do, if the files are all of different sizes then you'd have to store each file in one cell of a cell array. See the FAQ: https://matlab.wikia.com/wiki/FAQ#What_is_a_cell_array.3F

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

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by