- modify the DIR match string to suit your folder/filenames. Read the DIR documentation and experiment: always check the size of S before and after modifying the match string.
- if you do not want to simply discard the results (plots, values, whatever) of all loop iterations then you will also need to store or save those values or plots (e..g. by allocating to an output array, by exporting to file, by tiling plots on a figure, etc.).
How to plot all the graphs from different folder and save them in a different folder by name of folder
12 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
muhammad choudhry
il 15 Lug 2022
Commentato: Hong Tang
il 24 Mar 2024
Hi,
I have 44 folders in the path below and each folder have 1 excel file. Is there a way I can change the code below in a way that it will go into folder by folder and plot the graph using the data in that folder and save the graph in .emf format by the folder name in the path folder. Path is shown below as well as the code I am using. It is basically going to take me alot of time by doing one by one. I am also attaching the picture which will show folder names
Path where all the folders are: F:\3-PIV_Experimental_Data\Outlet_110\Data_LaserSheet_D\Data_PIV\6-VectorSatistics\PlotOverLine
Current Code: (Basically going one by one into folder and changing the path each time to save the graph)
files = ['F:\3-PIV_Experimental_Data\Outlet_110\Data_LaserSheet_D\Data_PIV\6-VectorSatistics\PlotOverLine\Run 13-33-42.Profile Plot.71gpvfq7\Export.71gpvfq7.000000.csv'];
a = readmatrix(files);
length=a(:,2);
U_x=a(:,11);
U_y=a(:,12);
U_m=a(:,25);
plot (length,[U_x,U_y,U_m],'-');
%Chart Representation
title('Velocities Across VFC (Below Outlet)');
xlabel('Distance(mm)');
ylabel('Velocities (m/s)');
legend('Velocities in x-direction','Velocities in y-direction','Resultant-Velocities')
0 Commenti
Risposta accettata
Stephen23
il 16 Lug 2022
Modificato: Stephen23
il 16 Lug 2022
"It is basically going to take me alot of time by doing one by one."
Don't! Computers are really only good at one thing: very simple tasks repeatedly in loops. When you copy-and-paste code like that you are just doing the computer's job for it.
Probably the simplest approach is to let DIR get the names of those subfolders and then you can simply loop over them:
P = 'F:\3-PIV_Experimental_Data\Outlet_110\Data_LaserSheet_D\Data_PIV\6-VectorSatistics\PlotOverLine';
S = dir(fullfile(P,'Run*Profile*','Export*.csv'));
% ^^^^^^^^^^^^^ % match subfolder names
% ^^^^^^^^^^^^ % match datafile names
for k = 1:numel(S)
F = fullfile(S(k).folder,S(k).name);
M = readmatrix(F);
% do whatever with the matrix M
end
Note:
4 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Get Started with MATLAB in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!