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.
No products are associated with this question.
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\xyzfile] @="XYZ Data"
[HKEY_CLASSES_ROOT\xyzfile\Shell\Open\command] @="\"C:\\Program Files\\MATLAB\\\\R2010a\\bin\\win64\\matlab.exe\""
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.
Play games and win prizes!Learn more