tags:

views:

81

answers:

3

I wrote a MATLAB script with gui which I also want to let my-coworkers use. Right now, I always start the gui-builder and run the program out of there. How can I package it together so that it is easy to use and preferably only one file or so. There is also a perl-script which is called out of the program. It only has to work for windows, if that is relevant.

EDIT: They don't all have MATLAB. But beside that, I think I am doing something wrong. The gui won't start if I double-click the script. And if I double-click the .fig-file, it will show the gui but will give me an error when I want to use it. It only works for me if I open the gui-builder, then open inside the gui-builder the .fig-file and then run the script from there.

A: 

If you're users have Matlab, they can double-click the script file and it should start Matlab and run the script automatically. Or...

When running a script 'myfile.m', use the following command:

matlab -r myfile

When calling a function 'myfile.m' which accepts two arguments:

matlab -r myfile(arg1,arg2)

http://www.mathworks.com/support/solutions/en/data/1-16B8X/index.html

Robert Harvey
+3  A: 

If your co-workers don't have matlab, you can compile it and package it into a stand alone executable. the process is pretty much straight forward.
To start, open the deployment tool with deploytool command, create a new project and drag your main .m file to the project. build it and then package it using the buttons at the top of the deployment tool.

shoosh
There's a demo at http://blogs.mathworks.com/videos/2007/12/12/advanced-matlab-compiling-a-gui/. deploytool and its command line equivalent mcc work well, but require the Matlab Compiler, which is (as usual) an extra cost option.
mtrw
+1  A: 

If you used GUIDE to generate the figure, it should have added the figure initialization code to the associated script. Do you see something like

gui_State = struct('gui_Name',       mfilename, ...
               'gui_Singleton',  gui_Singleton, ...
               'gui_OpeningFcn', @MyApp_OpeningFcn, ...
               'gui_OutputFcn',  @MyApp_OutputFcn, ...
               'gui_LayoutFcn',  [] , ...
               'gui_Callback',   []);

towards the top of the script? If you see it, but it's not working, you might have changed the names of the files or functions after you created them.

Or you might have to do all the linking between figure and script yourself using Handle Graphics. You need to use fighandle = open('YourFigName.fig'), then run through all the named objects in the fighandle and use set to specify the callbacks. Something like set(figHandle.MyPulldown, 'Callback', @myPulldownFncn).

mtrw
The figure intialization is there. To clarify, it runs fine when I start it with the gui-builder.
Lucas
These are the errors I am getting: ??? Error while evaluating uicontrol Callback??? Attempt to reference field of non-structure array....
Lucas
Have you tried stepping through the script in the debugger? I've never had the behavior you're describing, although I've also been able to foist off most of the GUIDE work onto various colleagues...
mtrw
I am stupid. It is working of course. I was clicking like an idiot on the .fig file.
Lucas
I tend to launch things from the prompt, so I guess I don't fall prey to that particular mistake. Many other mistakes are still available to me though.
mtrw

related questions