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

23 vues (au cours des 30 derniers jours)
muhammad choudhry
muhammad choudhry le 9 Mar 2022
Commenté : Walter Roberson le 10 Mar 2022
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

Réponse acceptée

Walter Roberson
Walter Roberson le 9 Mar 2022
Modifié(e) : Walter Roberson le 9 Mar 2022
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 commentaires
muhammad choudhry
muhammad choudhry le 10 Mar 2022
what was I doing wrong?
Walter Roberson
Walter Roberson le 10 Mar 2022
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.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur File Operations dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by