MATLAB: How to read Multiple CSV files in multiple sub folders

data acquisitionDatabase Toolboxtoolbox

Hi,
I want to read multiple csv files in a subfolder(s). I have a main folder, in this main folder many sub folders (here two). I want to read each sub folder, and merge all csv in that subfolder. The merged CSV file name should be the respective subfolder name.
I use the following code, but I am unable to proceed after that, I do not know how to read each subfolder and merge the CVS files.
After merged, I want to read each CSV from output folder, and extract the data in column E (Score).
Kindly some one help.
clc;
clear all;
close all;
inputFolder='D:\Mekala_Backupdata\Matlab2010\InputData';
outputFolder='D:\Mekala_Backupdata\Matlab2010\OutputData';
expList=dir(inputFolder);
isub=[expList(:).isdir];
expID={expList(isub).name};

Best Answer

You need to use genpath() to generate a list of all subfolders. Then you can use fullfile() and dir() to get a list of csv files in each one. See attached demo.
I would not use cd(). See the FAQ. I'd use fullfile() instead.