How to read and plot the data from csv files of subfolders?
11 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
0 commentaires
Réponse acceptée
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
Walter Roberson
le 10 Mar 2022
Were you using subdir() from the File Exchange? https://www.mathworks.com/matlabcentral/fileexchange/15859-subdir-a-recursive-file-search
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.
Plus de réponses (0)
Voir également
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!