How can I access data from folders?
22 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Code
files = dir('H:\Project Two\Programming and DataSet');
% Get a list of all files and folders in this folder.
names = {files.name};
% Get a logical vector that tells which is a directory.
dirFlags = [files.isdir] & ~strcmp(names, '.') & ~strcmp(names, '..');
% Extract only those that are directories.
subDirsNames = names(dirFlags);
Output
subDirsNames =
1×2 cell array
{'Instance01'} {'Instance02'}
Now, Instance01 folder has two files which are costMatrix.dat and ProcessMatrix.dat. Silmilarly, Instance02 folder has two files which are costMatrix.dat and ProcessMatrix.dat. First, I want to access and work on Instance01 folder and once it is done, I want to access and work on the Instance02. How can I do that?
0 comentarios
Respuestas (1)
Walter Roberson
el 13 de Jul. de 2020
files = dir('H:\Project Two\Programming and DataSet\*\*.dat');
names = fullfile( {files.folder}, {files.name} );
names will now be the fully-qualified names of .dat files, each with its appropriate folder name.
Note though that names will not be subdivided up into folders.
4 comentarios
Walter Roberson
el 17 de Jul. de 2020
sprintf('Instance%d', k)
should work if you want folders such as Instance1 Instance2 . Your earlier used Instance01 Instance02 which would correspond to
sprintf('Instance%02d', k)
Ver también
Categorías
Más información sobre Search Path en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!