Creating Custom File Associations

7 次查看(过去 30 天)
I work with data files that have their own file extension. We have created a large set of tools that decodes the data and allows us to perform our analysis. What I am trying to do in is associate this file type with MATLAB, so if I click on one of these files (I am using Windows 7) it will automatically open MATLAB and run the tool on the file.
I have written an open function for my file type which works fine when called from inside MATLAB and I can tell Windows to associate the file type with MATLAB, but when I click on the file it just opens MATLAB (regardless of whether it is already opened) and does nothing. Is there a way to fix this so it knows to run my openxzy function when it is trying to open a .xyz file?
Any help or suggestions are appreciated.
Greg
  1 个评论
Gregory
Gregory 2011-8-4
编辑:Gregory 2013-3-19
By diggering around in the registary I was able to find how to create a custom open with command. So when one of my files is clicked it calls matlab.exe -r open('"%1"'). However this always opens a new MATLAB session. I would like it to open in the existing session if there is one. Looking at how .m and .mat are opened in the registary, MATLAB is called from a different location (it has an @ on the font) and it passes a numberic option ( -58 for .m and -59 for .mat). Does anyone know anything about this or what it means?

请先登录,再进行评论。

采纳的回答

Gregory
Gregory 2011-8-18
编辑:Gregory 2013-3-19
I figured it out. First, and really the only MATLAB part, create an openxzy.m file and place it in MATLAB's startup path (probably Documents/MATLAB). Then in windows registry you have to replicate what .m, .mat, etcs files do. Here is what I have in my .reg file with explanation below:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\.xyz]
@="xyzfile"
[HKEY_CLASSES_ROOT\.xyz\OpenWithList]
@=""
[HKEY_CLASSES_ROOT\.xyz\OpenWithList\matlab.exe]
@=""
[HKEY_CLASSES_ROOT\.xyz\OpenWithProgids]
@=""
[HKEY_CLASSES_ROOT\.xyz\OpenWithProgids\xyzfile]
@=""
[HKEY_CLASSES_ROOT\xyzfile]
@="XYZ Data"
[HKEY_CLASSES_ROOT\xyzfile\Shell]
[HKEY_CLASSES_ROOT\xyzfile\Shell\Open]
@="Open"
[HKEY_CLASSES_ROOT\xyzfile\Shell\Open\command]
@="\"C:\\Program Files\\MATLAB\\\\R2010a\\bin\\win64\\matlab.exe\""
[HKEY_CLASSES_ROOT\xyzfile\Shell\Open\ddeexec]
@="open('%1')"
[HKEY_CLASSES_ROOT\xyzfile\Shell\Open\ddeexec\application]
@="shellverbs.MATLAB"
[HKEY_CLASSES_ROOT\xyzfile\Shell\Open\ddeexec\topic]
@="system"
This is more complicated than what is necessary to get it to work. You need to add two keys to the HKEY_CLASSES_ROOT (which requires admin privilages). One is for the exentension (.xyz). The default vaule of .xyz (xyzfile) is where windows will look when trying to open that file. The rest in that key is just making the open with menu look how I want it to.
xyzfile needs a subkey Shell, Shell needs a subkey Open (you can actually have others, just make the default value of Shell the same as the name of the subkey you want as a default command), Open needs a subkey command. The default value of command needs to be the full path of matlab.exe (which can also be followed with commands like -r). That is enough to get it working. The magic happens when you add the the subkey ddeexec with its two subkeys (application and topic with default values shellverbs.MATLAB and system respectively) to the Open key. You set the default value of ddeexec to the function you want called (%1 is Windows' veraible name for the file name) and it will be called in the existing MATLAB session if there is one and open one otherwise.
Since figuring this out I have easily added icons to .xyz files and functions to the right click menu of .mat files.
  2 个评论
Carl
Carl 2013-2-8
This is great! I got my custom extension to work fine is Matlab is already up and running.
However if it is not running I immediatly get an error that the file I just clicked was not found, Matlab opens and nothing happens, not even an error message. I think this might be due to the file using programs that are run during the initialisation phase of matlab. Is there a way to postpone the opening of the file until after the init phase is completed?
Gregory
Gregory 2013-3-19
I am not sure. However I am now trying to do the same thing in Linux. I am trying to figure out how to get it to open the file without opening a new session of MATLAB, so I will be trying to learn more about what shellverbs.MATLAB does for Windows.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Environment and Settings 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by