External Interfaces |
You can use DDE to notify a client application when data at a server has changed. For example, if you use MATLAB to analyze data entered in an Excel spreadsheet, you can establish a link that causes Excel to notify MATLAB when this data changes. You can also establish a link that automatically updates a matrix with the new or modified spreadsheet data.
MATLAB supports two kinds of advisory links, distinguished by the way in which the server application advises MATLAB when the data that is the subject of the item changes at the server:
You set up and release advisory links with the ddeadv
and ddeunadv
functions. MATLAB only supports links when MATLAB is a client.
This example establishes a DDE conversation between MATLAB, acting as a client, and Microsoft Excel. The example extends the example in the previous section by creating a hot link with Excel. The link updates matrix z and evaluates a callback when the range of cells changes. A push-button, user interface control terminates the advisory link and the DDE conversation when pressed. (For more information about creating a graphical user interface, see the online MATLAB manual, Creating Graphical User Interfaces.)
% Initialize conversation with Excel. chan = ddeinit('excel', 'Sheet1'); % Set range of cells in Excel for poking. range = 'r1c1:r20c20'; % Create a surface of peaks plot. h = surf(peaks(20)); % Get the z data of the surface. z = get(h, 'zdata'); % Poke the z data to the Excel spread sheet. rc = ddepoke(chan, range, z); % Set up a hot link ADVISE loop with Excel % and the MATLAB matrix 'z'. % The callback sets the zdata and cdata for % the surface h to be the new data sent from Excel. rc = ddeadv(chan, range,... 'set(h,''zdata'',z);set(h,''cdata'',z);','z'); % Create a push button that will end the ADVISE link, % terminate the DDE conversation, % and close the figure window. c = uicontrol('String','&Close','Position',[5 5 80 30],... 'Callback',... 'rc = ddeunadv(chan,range);ddeterm(chan);close;');
Example -- Importing Data From an Excel Application | Web Services in MATLAB |
© 1994-2005 The MathWorks, Inc.