Run a script that opens Matlab and performs a function

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?

 Respuesta aceptada

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 comentarios

Jason
Jason el 24 de Feb. de 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!
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"

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Startup and Shutdown en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 24 de Feb. de 2016

Comentada:

el 25 de Feb. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by