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

  • Thread starter Thread starter Beer-monster
  • Start date Start date
  • Tags Tags
    File Matlab
Beer-monster
Messages
285
Reaction score
0
Hi all

1. Homework Statement

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

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
 
Physics news on Phys.org
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:
script -g
to use the GUI dialog (or make that the default) and use
Code:
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:
script -o ExtraOption -f file
does the same as
Code:
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:

Similar threads

  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 2 ·
Replies
2
Views
5K
  • · Replies 3 ·
Replies
3
Views
6K
  • · Replies 4 ·
Replies
4
Views
2K
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
Replies
1
Views
4K