필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
Geeniee
Geeniee 2021년 2월 25일
댓글: Geeniee 2021년 2월 25일
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?

채택된 답변

madhan ravi
madhan ravi 2021년 2월 25일
편집: madhan ravi 2021년 2월 25일
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
Stephen23
Stephen23 2021년 2월 25일
편집: Stephen23 2021년 2월 25일
@madhan ravi: perhaps the function output should be changed to C.
madhan ravi
madhan ravi 2021년 2월 25일
Thank you Stephen.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Search Path에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by