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?

 채택된 답변

Walter Roberson
Walter Roberson 2016년 2월 24일
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

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"

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

태그

질문:

2016년 2월 24일

댓글:

2016년 2월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by