How to read and plot the data from csv files of subfolders?

11 次查看(过去 30 天)
Hi,
I am trying to read the csv files from the 48 subfolders and plot the data from each folder csv file onto the graph but it is only plotting the data from one file. I am not sure where I am going wrong? can anyone help? Below is the code.
Code:
files = subdir('F:\3-PIV_Experimental_Data\Outlet_110\Data_LaserSheet_D\Data_PIV\5-AverageFilter_VelocitiesExtration\Point_Velocities\Uy\*.csv');
for i = 1:numel(files)
filename = files(i).name;
data = readmatrix(filename);
Uy=data(1,2);
time = data(1,1);
plot(time,Uy,'*')
end

采纳的回答

Walter Roberson
Walter Roberson 2022-3-9
编辑:Walter Roberson 2022-3-9
projectdir = 'F:\3-PIV_Experimental_Data\Outlet_110\Data_LaserSheet_D\Data_PIV\5-AverageFilter_VelocitiesExtration\Point_Velocities';
files = dir( fullfile(projectdir, '*', '*.csv') );
filenames = fullfile({files.folder}, {files.name});
num_files = length(filenames);
all_Uy = zeros(num_files,1);
all_time = zeros(num_files,1);
for i = 1:numel(files)
filename = filenames{i};
data = readmatrix(filename);
all_Uy(i) = data(1,2);
all_time(i) = data(1,1);
end
scatter(all_time, all_Uy, '*');
  2 个评论
Walter Roberson
Walter Roberson 2022-3-10
If so then the equivalent would be
files = dir( fullfile(projectdir, '**', '*.csv') );
Anyhow, the error was that you were only pulling out the file name from the directory information, without pulling out information about which directory the file was in.

请先登录,再进行评论。

更多回答(0 个)

类别

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