5.0

5.0 | 2 ratings Rate this file 23 Downloads (last 30 days) File Size: 14.3 KB File ID: #9723

filefun: Apply a function to files

by

 

22 Jan 2006 (Updated )

Adds multi-file functionality to functions handling only single files.

Editor's Notes:

This file was a File Exchange Pick of the Week

| Watch this File

File Information
Description

FILEFUN is created in the same spirit as e.g. CELLFUN, in that it repeatedly calls the same function FUN with different arguments, in this case filenames. It will then collect the output(s) of the function into concatenated arrays of the same type as FUN delivers, or encapsulated individually in cell arrays.

The filename argument to FILEFUN may contain wildcards(*) and FILEFUN may optionally traverse subdirectories recursively.

FILEFUN can also be called without the FUN argument, turning it into a recursive wildcard file finder.

See 'help filefun' for extensive help and more examples.

Examples:

Open all figure files in current directory:

filefun(@openfig,'*.fig')

Pick a couple of image files and compute their mean RGB values:

pth=fullfile(matlabroot, 'toolbox', ...
             'matlab', 'demos', 'html', filesep);
[filenames,pathname]=uigetfile('*.png','Pick files', ...
                    pth,'MultiSelect', 'on');
fun=@(fn) squeeze(mean(mean(imread(fn))))';
mn=filefun(fun,strcat(pathname,filenames))

Acknowledgements

Parse Pv Pairs inspired this file.

MATLAB release MATLAB 7.1.0 (R14SP3)
Other requirements Please notify the author of bugs by email
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (3)
19 May 2011 Nitin  
24 Jan 2006 John D'Errico

Sorry. It does indeed run quite nicely on the mac. The author referred to '\' in his comments, but uses filesep in the code itself. Very good. A great tool if you wish to process evey jpeg file in a directory tree, or a variety of other tasks.

24 Jan 2006 John D'Errico

This looks very nice. I can only offer one enhancement - instead of using the fixed '\' as a separator in paths, use filesep instead. Filesep provides the correct separator for various operating systems. For example, a mac needs '/'.

Updates
31 Jan 2006

1.1 Fixed erroneous NaN option of UniformOutput.
Usage of NaN is discouraged.Instead, UniformOutput can now be entered as a
logical, making it congruent with CELLFUN et.al.
Path can now be entered as [], as well as ''.

17 Feb 2006

New parameter: CheckExistence.
Change in comments.

16 Mar 2006

Gives better error info when no error handling routine is specified.

17 Mar 2006

Uploaded the old version by mistake in previous update.

15 Feb 2007

Removed the PATH argument.

Made the List parameter false by default if a function handle is given as first argument.

Note: These changes will break some old code, but I think the advantages are worth it.

Contact us