Effacer les filtres
Effacer les filtres

How do I save filenames in a for loop for later access?

1 vue (au cours des 30 derniers jours)
Geeniee
Geeniee le 25 Fév 2021
Commenté : Geeniee le 25 Fév 2021
I'm able to iterate through a given folder and display the names of all files. However, I want to save the names so did I can do work on each file. For example,
function fn = filnamn(katalog)
% displays the names of all files in given diretory
% Called with name of desired directory
fn = dir(katalog);
for k = 1:numel(fn)
if ~fn(k).isdir
disp(fn(k).name);
end
end
After each iteration how would I "append" each file so did I can access them afterwards?

Réponse acceptée

madhan ravi
madhan ravi le 25 Fév 2021
Modifié(e) : madhan ravi le 25 Fév 2021
C = cell(nnz(~fn(k).isdir), 1); % before loop
function C = filnamn(katalog)
% displays the names of all files in given diretory
% Called with name of desired directory
fn = dir(katalog);
for k = 1:numel(fn)
if ~fn(k).isdir
C{k} = fn(k).name;
end
end
  5 commentaires
Stephen23
Stephen23 le 25 Fév 2021
Modifié(e) : Stephen23 le 25 Fév 2021
@madhan ravi: perhaps the function output should be changed to C.
madhan ravi
madhan ravi le 25 Fév 2021
Thank you Stephen.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Search Path 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