- Undocumented Matlab - https://undocumentedmatlab.com -

Matlab DDE support

Posted By Yair Altman On July 21, 2010 | 7 Comments

Windows DDE [1] was a 1990’s technology used to transfer control between Windows applications. DDE was fully supported and documented in old Matlab releases (R13 [2], R14 [3]). DDE is no longer documented in Matlab, although it apparently still works. In fact, Matlab says [3]:
As of MATLAB version 5.1, all development work for the DDE Server and Client has been stopped and no further development will be done. The MathWorks strongly recommends that you migrate to the MATLAB interface to COM technology that is documented.
In the past decade, DDE has been superseded by newer Windows technologies deriving from COM [4], which is supported by Matlab. However, DDE is still used for some Windows infrastructure functions such as cut/copy/paste (CCP) and the Windows Shell file association. Today’s article, based on information given to me by Martin Höcker, a reader of this blog, uses this fact to interface the Windows Explorer with Matlab.
Martin works on an experiment that outputs a large number of small data files that have a “THe” extension. He wrote a Matlab script that parses and plots the data files individually. This script is called “THePlotter.m” and is on the Matlab path. But calling this script with the command “THePlotter(‘D:\Data\somedata.THe’)” in Matlab’s console is tedious, especially if we need to check hundreds of files.
Since all data files have the same “.THe” extension, Martin associated this file type with Matlab so double-clicking any file in Explorer will plot the data in Matlab. It is very easy to set this up using DDE:

  1. associate the “.THe” file type with Matlab as shown below (note: use the MATLAB.exe file in the /bin/win32 or /bin/win64 subfolder). Now Matlab will generate an error for a double-click on the file, but we don’t care.
    Associating an extension with Matlab (click for details) [5]
    Associating an extension with Matlab (click for details)
  2. in Windows Explorer, click on Tools / Folder Options / File Types
  3. select the “.THe” extension and click “Advanced”
    Editing the file association details [6]
    Editing the file association details
  4. set this to be the default action upon mouse double-click or keyboard ENTER
  5. select the “open” action, and click “Edit…”
  6. rename the action “plot” (renaming is optional) and click the “Use DDE” checkbox
  7. enter the DDE information as seen below:

Windows Explorer settings (click for details) [7]
Windows Explorer settings (click for details)

It is even possible to have several “actions” for the file: Martin has “Plot”, and “Add to plot”, which allows plotting multiple files at once by simply choosing “Add to plot” with a right click in Windows Explorer:
Windows Explorer use (click for details) [8]
Windows Explorer use (click for details)

Behind the scenes, all this is simply a GUI wrapper for adding/modifying the Windows Registry:
Registry entry for the Shell file association
Registry entry for the Shell file association

Note that despite some information in the R13/R14 documentation, we do not need to run Matlab with the /Automation startup flag (or any other special modification for that matter), at least in recent Matlab releases.
The biggest advantage of using DDE: It does not open up a new instance of Matlab whenever you click on a file. This saves an incredible amount of start-up time.
One thing we cannot do, is to pass parameter/value pairs to the “THePlotter” function. The problem possibly lies in the way that Matlab parses the DDE commands – the parameter is enclosed by quotes, and Matlab seems to turn these quotes into double-quotes, and then chokes on itself…
Have you found another neat trick to enhance your work-flow? If so, please share it in the comments [9] section below, or send me an email [10]
p.s.: Readers who are interested in using Matlab’s DDE functionality programmatically, are welcome to read and use the following semi-documented built-in functions: ddeadv, ddeexec, ddeinit, ddepoke, ddereq, ddeterm, ddeunadv. These functions have a readable help section, but no doc page nor official support.

Categories: Medium risk of breaking in future versions, Semi-documented function, Undocumented feature


7 Comments (Open | Close)

7 Comments To "Matlab DDE support"

#1 Comment By Pooh On August 1, 2010 @ 03:47

Hi,

Thanks a lot for this feature, It works well and will save me a lot of time (changing working directory, specify the file to open).

I’ve a question about compiled matlab application : is it possible to call DDE with a matlab compiled app (MCR) ?

I’ve a gui that read and process files and i deploy this gui in a compiled version. The non-compiled version can now open files directly from windows explorer (thx to this post). How can i do it with the compiled version if this is possible ?

Thx a lot

#2 Comment By Yair Altman On August 1, 2010 @ 06:28

@Pooh – I do not know how DDE behaves in a compiled application. I suspect that since MCR uses the same Matlab engine as the interactive application, DDE will also work with MCR, but I do not know. The easiest way to find out is to simply try it out (don’t worry – it will not explode in your face…)

#3 Comment By Pooh On August 2, 2010 @ 22:36

Thx,

Since last time i’ve made a script that manage all my DDE file association (initializatiojn by writing in the registry (even file icon) and open , plot of file)

I’m certain i’ve read somewhere that compiled scripts and gui cannot have input argument.
So i’m not quite sure how to use DDE.
I’ll try and post after.

I’ll also try mulitselection.

#4 Comment By Pooh On August 9, 2010 @ 04:00

Hi

About compiled app:
After compilation, there’s the *.exe
-> myfun.exe
I’ve associate my extension file with the executable (Step 1).
When I open the file, myfun.exe is launched with one input arg: the path and file. It’s the same as %1 in dde.

So, with a little adaptation, it’s easy to launch the file:

function  myfun(args)
   if nargin==1 && exist(args{1},'file')==2
      launch_file(args{1})
      return;
   end
end

This code is ok for guis.

I also wanted to explore multiselect open, but it seem a little bit more tricky: a multiselect on files then open just launch n-times the single file opening instruction.

#5 Comment By Jonas On August 8, 2011 @ 04:59

Cool stuff! About the “thing we cannot do”, i.e. passing several parameter/value pairs: From my tests with MATLAB R2010b it seems that MATLAB uses a greedy string parser here: everything between the first and last quote is treated as one string parameter. So, if your DDE command is THePlotter(‘filename.THe’, ‘somestring’, 2)
then this is interpreted as two parameters:
1) string: “filename.THe’, ‘somestring”
and
2) double: 2

… so in principle not something you couldn’t recover from using eval().

#6 Comment By Martin Höcker On June 17, 2013 @ 10:28

After upgrading to Matlab2013a, it took me a while to figure out that Mathworks has changed the DDE “Application Name”. It now includes the Matlab Version number, which for Matlab2013a makes it “ShellVerbs.Matlab.8.1.0.”. Just in case other people are wondering about this too, I made a small note on StackExchange.

#7 Pingback By Why does Windows explorer open multiple instances of Matlab2013a when I am using DDE-commands? | BlogoSfera On June 17, 2013 @ 11:02

[…] Windows explorer uses DDE to communicate with applications for things like file-opening, and the DDE-commands can be set in the “folder options” of Windows explorer. Matlab has an undocumented DDE-interface, which I use for telling Matlab to analyze the selected file. […]


Article printed from Undocumented Matlab: https://undocumentedmatlab.com

URL to article: https://undocumentedmatlab.com/articles/matlab-dde-support

URLs in this post:

[1] Windows DDE: http://en.wikipedia.org/wiki/Dynamic_Data_Exchange

[2] R13: http://www.mathworks.com/access/helpdesk_r13/help/techdoc/matlab_external/ch07cl21.html

[3] R14: http://www.system.nada.kth.se/unix/software/matlab/Release_14.1/techdoc/matlab_external/ch8_co28.html

[4] COM: http://en.wikipedia.org/wiki/Component_Object_Model

[5] Image: http://undocumentedmatlab.com/images/DDE_Explorer_Associate.png

[6] Image: http://undocumentedmatlab.com/images/DDE_Explorer_Edit.png

[7] Image: http://undocumentedmatlab.com/images/DDE_Explorer_Settings.png

[8] Image: http://undocumentedmatlab.com/images/DDE_Explorer_Use.png

[9] comments: http://undocumentedmatlab.com/blog/matlab-dde-support/#respond

[10] send me an email: mailto:%20altmany%20@gmail.com?subject=Undocumented%20Matlab&body=Hi%20Yair,%20&cc=;&bcc=

[11] HTML support in Matlab uicomponents : https://undocumentedmatlab.com/articles/html-support-in-matlab-uicomponents

[12] Matlab installation woes : https://undocumentedmatlab.com/articles/matlab-installation-woes

[13] Using pure Java GUI in deployed Matlab apps : https://undocumentedmatlab.com/articles/using-pure-java-gui-in-deployed-matlab-apps

[14] Types of undocumented Matlab aspects : https://undocumentedmatlab.com/articles/types-of-undocumented-matlab-aspects

[15] Matlab and the Event Dispatch Thread (EDT) : https://undocumentedmatlab.com/articles/matlab-and-the-event-dispatch-thread-edt

[16] handle2struct, struct2handle & Matlab 8.0 : https://undocumentedmatlab.com/articles/handle2struct-struct2handle-and-matlab-8

Copyright © Yair Altman - Undocumented Matlab. All rights reserved.