Creating Custom File Associations

조회 수: 7 (최근 30일)
Gregory
Gregory 2011년 7월 22일
편집: Gregory 2016년 6월 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