4

I want open a GUI directly from desktop without opening MATLAB and run it from it. When I right click on the main MATLAB code file and select Run in windows environment, MATLAB starts and after that my GUI automatically runs but I want have this with double clicking on an Icon (shortcut) o desktop. How can I do this? I don't want compile my app.

  • My GUI contains training neural network so I can't compile it.
Cœur
  • 37,241
  • 25
  • 195
  • 267
Eghbal
  • 3,892
  • 13
  • 51
  • 112
  • Maybe this will help: http://stackoverflow.com/questions/15678762/running-a-gui-requires-opening-the-fig-file-in-guide – Dev-iL Aug 03 '14 at 07:56
  • @Dev-iL. Thank you but technically I think I need a trick in windows and creating shortcut to run the code not open it. – Eghbal Aug 03 '14 at 07:58
  • What you want, is to be able to double click `.m` files and have them execute in MATLAB. It is not something specific for GUIs. Which OS are you using? – Dev-iL Aug 03 '14 at 08:00
  • Yes. That's true. as you said we don't need any changing in codes because when we right click on the file and select run we can run it directly in windows environment. We want some trick to create a shortcut to run not open the file. – Eghbal Aug 03 '14 at 08:02
  • The only way possible I think other than creating an app, would be creating an EXE with `mcc`. – Divakar Aug 03 '14 at 08:44
  • @Divakar. The problem is my GUI contains training neural network so I can't compile it. – Eghbal Aug 03 '14 at 08:50

1 Answers1

6

What you actually need is a way to run .m files via the command line - an action which isn't specific to GUIs. A command line operation is something you can bind to a shortcut on your desktop or execute using a batch file.

The solution you're looking for is a combination of MATLAB-specific syntax and a straightforward batch file creation procedure:

  1. Open a text editor.

  2. Write this inside: "C:\<path to your MATLAB folder>\matlab.exe" -nodisplay -nosplash -nodesktop -r "cd('C:\<path to your where the .m file is>\'); run('C:\<path to where the .m file is>\mfile.m');"

  3. Save the file as .bat (in windows) and run.

Community
  • 1
  • 1
Dev-iL
  • 23,742
  • 7
  • 57
  • 99