Run a script that opens Matlab and performs a function

2 views (last 30 days)
I want to be able to save a .m file to my desktop, and when I click it it will open matlab and run its self. Is there a way to do this?

Accepted Answer

Walter Roberson
Walter Roberson on 24 Feb 2016
I don't know if it is impossible, since MS Windows allows some pretty odd behaviours to be configured on NTFS filesystems by using the Alternate Streams facilities. The .m file would effectively become the mount point for an application too run in... I suspect it might just be doable. I hesitate to guess at the amount of work involved.
On the other hand, you could so something very similar by creating a .bat that ran the function using the MATLAB startup flag "-r" followed by a MATLAB command. For example,
"C:\Program Files (x65)\MATLAB\R2018g\bin\intel\matlab.exe" -r "try run('C:\Users\Jason\Documents\MATLAB\Plan9\outer_space.m'); catch; quit"
  2 Comments
Jason
Jason on 24 Feb 2016
Straight up awesome. Thank you. I removed the "try", "catch" and "quit" from the line of code you provided. Because I want MATLAB to stay open, and I kept getting errors with the try and catch commands.
I have never written a .bat file, but with those specific commands removed It works as I hoped it would.
Thanks so much man!
Walter Roberson
Walter Roberson on 25 Feb 2016
I forgot the 'end' on the 'try'
"C:\Program Files (x65)\MATLAB\R2018g\bin\intel\matlab.exe" -r "try run('C:\Users\Jason\Documents\MATLAB\Plan9\outer_space.m'); catch; end; quit"

Sign in to comment.

More Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!