Filter löschen
Filter löschen

function call

1 Ansicht (letzte 30 Tage)
Baba
Baba am 14 Nov. 2011
To tell my function to perform it's operations on files in a directory Function('directory') is the command for that. how do I tell this function to perform it's operations on only the first n files in that directory and not all of the files.

Antworten (2)

Grzegorz Knor
Grzegorz Knor am 14 Nov. 2011
Something like that:
function my_fun(directory,n)
a = dir(directory);
% a(1) is folder '.'
% a(2) is folder '..'
% so you have to start from a(3)
for k=3:n+2
disp(a(k).name)
% do more operation on folder/file
end
  5 Kommentare
Fangjun Jiang
Fangjun Jiang am 14 Nov. 2011
Using a=a(~[a.isdir]) should solve the problem!
Walter Roberson
Walter Roberson am 14 Nov. 2011
dir() is *not* defined to return . and .. first in any of the operating systems. dir() is defined to return the order that the operating system returns. In turn, the order returned by the operating system can depend upon the file system type -- some filesystems sort directories contents automatically and some do not (and some use tree structures.)

Melden Sie sich an, um zu kommentieren.


Image Analyst
Image Analyst am 14 Nov. 2011
Can't you specify a file extension to dir() and get only those specific files and not any directories?

Kategorien

Mehr zu File Operations finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by