Doug's MATLAB Video Tutorials

September 27th, 2007

MATLAB Basics video: UIGETFILE for selecting a file in a script, function or GUI

This is one in a series of videos covering MATLAB basics. It is meant for the new MATLAB user. This video covers how to use UIGETFILE to make it easier to select a file from a script, function or GUI.
Find the files here. Other videos have been gathered here: http://blogs.mathworks.com/pick/category/video/ Other MATLAB Basics posts have been gathered here: http://blogs.mathworks.com/pick/category/matlab-basics/

5 Responses to “MATLAB Basics video: UIGETFILE for selecting a file in a script, function or GUI”

  1. Eli replied on :

    Say I use uigetfile to get a filename that is in a path not currently part of the matlab path. When I execute the next line of code (load(fileName)), the file will not be loaded since it is not in the current path. How can I go about adding the path (automatically/ without additional user input)?

    Cheers,
    Eli

  2. Bob replied on :

    Eli, does this help?

      [f,p] = uigetfile;
      load(fullfile(p,f))
    

    Cheers
    Bob

  3. Fredrik replied on :

    Thanks for these excellent videos. However, I am having some problems. I am trying to use the uigetfile to load a matfile without a .mat extension into the matlab workspace. I have had no problem doing this using the simple line:

    load 18-dots.nirs -mat;
    

    however, when I try this with the uigetfile I keep on getting error messages.

    The scripts I have tried are:

    
    fileName = uigetfile('*.nirs')
    
    load(fileName) -mat;
    

    or

    
    fileName = uigetfile('*.nirs')
    
    load fileName -mat;
    

    Help is appreciated.

    Cheers,

    F

  4. dhull replied on :

    @Fredrik,

    What are the error messages?

    Doug

  5. Fredrik replied on :

    Doug,

    the error message I get for the first script is:

    “??? Error using ==> load
    Number of columns on line 1 of ASCII file C:\Documents and Settings\ft20\Desktop\Matlab Scripts for Nirs\Insert
    Stim Marks\22-dots_fixed.nirs
    must be the same as previous lines.”

    and for the second I get:

    “??? Error using ==> load
    Unable to read file fileName: No such file or directory.”

    Thanks,

    F

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).


MathWorks

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.