필터 지우기
필터 지우기

Can I put the filenames in a directory in a matlab vector?

조회 수: 5 (최근 30일)
John
John 2012년 1월 11일
In unix, this is simply: ls . > filename and then you can point to each filename with 'foreach'. Is there a complementary way to do the same thing in matlab?

답변 (2개)

Walter Roberson
Walter Roberson 2012년 1월 11일
fileinfo = dir();
for K = 1 : length(fileinfo)
disp(fileinfo(K).name)
end
  댓글 수: 4
Walter Roberson
Walter Roberson 2012년 1월 12일
Sorry, allow me to correct that:
fileinfo = dir();
for K = 1 : length(fileinfo)
foreach(fileinfo(K).name)
end
Where you have defined a function named "foreach" that does whatever you want done with the file. For example,
function foreach(FileName)
%take an action on the given file
disp(FileName); %action chosen was to display the file name
end
You will find, by the way, that there is no "foreach" command in Unix; you can check the Single Unix Specification at the OpenGroup.Org site.
"foreach" is, however, a command defined in some command shells, especially command shells derived from C Shell -- which is not part of the Single Unix Specification; see http://pubs.opengroup.org/onlinepubs/007904875/xrat/xcu_chap02.html
http://www.grymoire.com/Unix/Csh.html#uh-30
John
John 2012년 1월 12일
Yes, thanks. I had forgotten that 'foreach' was a shell command.

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


Daniel Shub
Daniel Shub 2012년 1월 12일
What about just doing it as a system call.
system('ls . > filename')

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by