is there a better way of accessing the csv files from each folders in the path below?
Show older comments
Hi,
I am using the code below to plot the data but the problem is code is not efficient enough to save me more time. I have 4 paths with csv in them and each csv will go from timestamp 000000.csv to 000100.csv in each folder and I need to plot the data from each csv from each folderwith the same time stamp. I can goahead and do the same way in the code below but is there any better way of analysing the data then what I have below.
files = { 'F:\3-PIV_Experimental_Data\Outlet_110\Data_LaserSheet_D\Data_PIV\Data_Vector\Run 13-56-31.Adaptive PIV.6tvk0mbp\Export.6tvk0mbp.000000.csv'; ...
'F:\3-PIV_Experimental_Data\Outlet_110\Data_LaserSheet_B\Data_PIV\Data_Vector\Run 17-19-03.Adaptive PIV.6ul4ynyv\Export.6ul4ynyv.000000.csv'; ...
'F:\3-PIV_Experimental_Data\Outlet_110\Data_LaserSheet_B\Data_PIV\Data_Vector\Run 17-19-03.Adaptive PIV.6ul4ynyv\Export.6ul4ynyv.000000.csv'; ...
'F:\3-PIV_Experimental_Data\Outlet_110\Data_LaserSheet_A\Data_PIV\Data_Vector\Run 12-45-51.Adaptive PIV.6tskdx6a\Export.6tskdx6a.000000.csv'};
for i = 1:numel(files)
a = readtable(files{i});
X = a{:,5}/1000;
Y = a{:,6}/1000;
U = a{:,9};
V = a{:,10};
quiver(X, Y, U, V, 10);
axis tight
hold on
end
Accepted Answer
More Answers (1)
Image Analyst
on 5 Jan 2022
How about getting all the filenames and looping over them.
topLevelFolder = 'F:\3-PIV_Experimental_Data\Outlet_110\';
filePattern = fullfile(topLevelFolder, '**/Export*.csv'); % The ** will make it recurse into subfolders.
fileList = dir(filePattern);
for k = 1 : length(fileList)
thisFolder = fileList(k).folder;
thisBaseFileName = fileList(k).name;
fullFileName = fullfile(thisFolder, thisBaseFileName);
data = readtable(fullFileName);
end
You might have to do some further parsing if you want to process subsets of the entire list in some particular order.
Categories
Find more on National Instruments Frame Grabbers in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!