Call two folders (or directories) with the same file in the script
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Jacqueline Rigatto
le 26 Juil 2021
Commenté : Jacqueline Rigatto
le 5 Août 2021
Hi, I would like to know how I call two folders (or directories) with the same file in the script to make a graph
The folders (or directories) are:
C:\Users\Jacqueline\ERA5\Downloads\O1
C:\Users\Jacqueline\ERA5\Downloads\O2
And the file is: ERA5_2010.nc (both have the same file)
Thank you very much in advance
0 commentaires
Réponse acceptée
dpb
le 26 Juil 2021
basedir='C:\Users\Jacqueline\ERA5\Downloads\';
fn='ERA5_2010.nc';
N=2;
for i=1:N
fqn=fullfile(basedir,num2str(i,'%02d'),fn); % build fully-qualified filename
data=..... % read the file here
% do whatever with this dataset here before finishing loop to go to next
...
end
Above is simplest "dead-ahead" to read the fixed number of subdirectories and process each file in turn.
Enhancements begin with using dir to find out how many subdirectories there are so far and iterating over all of them or to build a list and let the user select desired ones.
To keep the data, use a cell array to hold each returned result so don't overwrite each time through the loop.
All sorts of other possibilities will come depending upon just what need to do...
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!