1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Matlab: Open file with typed filename and/or uigetfile?

  1. Jun 1, 2015 #1
    Hi all

    1. The problem statement, all variables and given/known data

    I have a function script for doing some analysis of data from a text file and making some plots. My script takes the filename as an input argument - this is very helpful for running the analysis over multiple files and replicating results.

    However, I have also found it helpful to be able to browse for the file using the command uigetfile.

    So I have two versions of the same analysis script: one that requires a filename and one that opens a dialog box. This quite inefficient and awkward and it would be great if I could use a single script.

    The ideal solution would be to have the code branch so that if a filename is provided that file is opened as normal, else a dialog box would appear if no name was provided (i.e. an empty argument.)

    3. The attempt at a solution

    I've googled around and searched mathworks, but have not found anything that helpful. Would anyone be able to point me in the direction of a solution?

    Thanks for your help.


    BM
     
  2. jcsd
  3. Jun 1, 2015 #2
    Does this help http://www.mathworks.com/matlabcent...-when-running-matlab-in-batch-mode-in-windows

    You could try to build something like options in command line programs.
    For example use
    Code (Text):
    script -g
    to use the GUI dialog (or make that the default) and use
    Code (Text):
    script -f /location/to/file.dat
    whenever you know where to find the file.

    I must say that I don't know how matlab handles these kind of things, the above idea, although the link above might give you further leads.

    The advantage of the mentioned method is that you can use multiple options at once without bothering about the position.
    So
    Code (Text):
    script -o ExtraOption -f file
    does the same as
    Code (Text):
    script -f file -o ExtraOption
    Edit;
    added some information for doing this in C, it might give you an idea of how to implement this.
    http://courses.cms.caltech.edu/cs11/material/c/mike/misc/cmdline_args.html
    http://www.thegeekstuff.com/2013/01/c-argc-argv/
     
    Last edited: Jun 1, 2015
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: Matlab: Open file with typed filename and/or uigetfile?
  1. Type in matlab form (Replies: 12)

Loading...