Doug’s MATLAB Video Tutorials

September 9th, 2008

Advanced MATLAB: File name processing from directory listing

Very often MATLAB users want to be able to process a set of files from a directory. In this video, I show how you can look through a directory seeking files of the form “data###.dat” and then returning the “###” as a number with any leading zeros removed. This makes use of regular expressions, but does not explain their theory much at all.
iconFiles.jpg This is not the first time this kind of thing has been discussed. Check out Loren’s take, or Steve’s take from their blogs.

6 Responses to “Advanced MATLAB: File name processing from directory listing”

  1. david replied on :

    nice. just a thought:
    rather than trying ideas in the command window, one idea is to do this using the editor in cell mode. that way, when you’ve figured out the right syntax, you almost have a finished script. this also saves scrolling through the command history for the correct version of each command which after trial-and-error often look similar to versions that don’t quite work

    regards,
    david

  2. matt fig replied on :

    Off topic, but David’s reply made me think about an enhancement I would like to see. Imagine scrolling up through the command history, either through the editor or by using the up arrow. When you came across a command that caused an error, it would be in red font. Boy that would make life simpler when looking through several similar commands, some of which didn’t work.

  3. Doug replied on :

    David,

    Actually, I tend to do a little bit of both. It is hard to say when I work at the command line and then script and when I write a script and just keep running it as you add to it.

    Doug

  4. Doug replied on :

    Matt,

    That is an excellent suggestion. I just posted it to our internal enhancement tracking database. You can make such requests more reliably by e-mailing support@mathworks.com

    Thanks,
    Doug

  5. onassis replied on :

    I saved a big(>2GB) .mat file on an external HD using
    save -v7.3 myfile.mat filetosave

    I try loading the file back
    with
    load myfile.mat
    and get an error message that file cannot be read.
    Any help?

  6. dhull replied on :

    @onassis

    Have you tried the procedure with a much smaller dataset to make sure you are doing everything right? If it works with a smaller dataset, then we can take it from there.

    Doug

Leave a Reply

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>

If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).


Doug Hull is a proud MathWorker who is on a mission to help you with MATLAB.

Doug's picture

These postings are the author's and don't necessarily represent the opinions of The MathWorks.