Creating a desktop shortcut to run an mfile, Windows 7

15 views (last 30 days)
Hey Everybody,
I have a couple questions about creating desktop shortcuts to run an mfile.
I would like to create a desktop shortcut that when clicked will run the mfile (not just open it). In addition to this, I would like to be able to distribute the mfile to others and still have the shortcut work. I am having lots of problems with getting the "relative path" required for the shortcut to work.
The two areas I need help with is:
1. (Most Important) Having other people be able to use my shortcut. Right now, I can put my shortcut anywhere on my computer and it will work fine. The problem is that when another person tries to use the shortcut, it points to the directory that was on my computer. I looked online extensively and realized I think this is really complex, maybe not with MATLAB, but at least with other directories. Ideally I think we just need to make a relative path from where the shortcut is located (this stays constant) but I think that is harder to do than you would initially think.
2. Assuming I can get the above working, I would like to set the default action of the shortcut to run the mfile, not just open it up in the editor. I am assuming this would involve a command line process, but I am open to any ideas or suggestions.
I have a feeling my ending solution will involve creating a shortcut to a .bat file which is OK, I am just not very familiar with DOS commands and what not so would probably need some extra guidance if that indeed is the solution.
Thank you in advance for your help!

Accepted Answer

Geoff
Geoff on 31 May 2012
A batch file to do this is almost exactly the same as a shortcut. You still need to know the MatLab install path. Now, I did a standard installation of MatLab, and I have found that it has put the MatLab bin directory into my path.
Hit Windows-R, type cmd and hit Enter. Then type path and press Enter. You should see MatLab in there. If you want to exploit this, the caveat is that if there are multiple MatLab installations, you can't control which one it will run. But the bonus is you don't need to know which one they have. They probably only have one anyway.
So, you should be able to create a batch file in the same directory as your script (call it myscript.bat), and put the following in:
@echo off
matlab -nosplash -r "myscript"
Where myscript is the name of your script or function to run.
You may wish to run "myscript; quit" -- I don't know what your purposes are.
If your script has multiple subdirectories I can help you dynamically set the MatLab search path. Otherwise I'll forget that and keep this simple.
The only trick now, is that a user might want a shortcut to this batch file, which they will have to do manually. Unless, I suppose, you wanted to create an installation script (which you could probably write in MatLab).....
  3 Comments
Geoff
Geoff on 31 May 2012
Errr, no.. I don't think you can set the icon on a batch file. You'd need to come up with some other way. Perhaps a standalone program that invokes the batch file? Overkill, really. Maybe you can make a relative shortcut in that directory (ie no paths).
The -nosplash prevents MatLab from showing the splash screen at startup. You might not want that switch. You can look at the command line options if you type 'doc' in the command window, and then enter 'matlab' in the search box. It's should be the first entry that comes up.
wind king
wind king on 17 Jan 2019
thank you for your answer。do you kow how to setup matlab on web view page with a Hyperlink?

Sign in to comment.

More Answers (0)

Categories

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

Community Treasure Hunt

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

Start Hunting!