100% found this document useful (1 vote)
562 views

How To Connect Matlab and Delphi 7

This document describes how to connect Delphi 7 and Matlab 7 using Matlab's automation server. The process is simple but documentation is limited. Matlab's automation server allows executing Matlab commands from other environments like Delphi. The example loads data from a file into Matlab using PutWorkspaceData and plots it using Execute. It creates a Matlab application object in Delphi, makes it visible, loads the data file into the Matlab workspace, and plots the data.

Uploaded by

Bogdan Vicol
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
562 views

How To Connect Matlab and Delphi 7

This document describes how to connect Delphi 7 and Matlab 7 using Matlab's automation server. The process is simple but documentation is limited. Matlab's automation server allows executing Matlab commands from other environments like Delphi. The example loads data from a file into Matlab using PutWorkspaceData and plots it using Execute. It creates a Matlab application object in Delphi, makes it visible, loads the data file into the Matlab workspace, and plots the data.

Uploaded by

Bogdan Vicol
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

How to connect Matlab and Delphi 7

By Corzo
This article describes the process of connecting a delphi code with Matlab 7 automaton server

Delphi 7 is a complete developing language, and Matlab 7 have so many engineering toolbox and ploting tools. So if we can combine them, it will be a powerfull graphical interface plus the best mathematical tool. This process is very simple, however, the first time i tried to find information about it was very difficult. The matlab automation server allows to execute any command as if you where inside the matlab enviroment but from any other enviroment, even office. In this case the example uses DELPHI. The code i am presenting here is to load data from a filename given from delphi and execute a plot function (Time series). But as you will see is just an example and can be used to execute any other function. The matlab by default doesnt register the libraries for this comunication, so you will need to go to the command line, in the folder <MATLAB7\BIN\WIN32> and type mwregsvr mwcomutil and mwregsvr mwcommgr. Now you are ready to call matlab from DELPHI. First open a project. In side the form create two buttons, in this case i used Bitbutton. So you can se in the procedure Form1.BitBtn. one of the buttons is to connect with matlab, the other one is just to close the form. Delphi requires some libraries to comunicate with COM objects. In this case you need to add to the standard ones ComCtrls, ComObj, which are the ones that allow the communication uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Menus, StdCtrls, Buttons, ExtCtrls, ComCtrls,ComObj; Then inside one of the buttons, create the OLE object, this is done by instruction CreateOleObject. After this you just need to apply anyone of the function available for the communication. Which are not so much in principle (TABLE 1). But are enough. You can see that in this first button the option visible is set to 1, these is because i wanted to use matlab while delphi was running, so you can leave it in 0. This process delays a little depending on the processor you are ussing, but after it loads is much faster. <CODE>procedure TForm1.BitBtn2Click(Sender: TObject); var name:string; begin MatApp:=CreateOleObject('matlab.application'); MatApp.visible:=1; end; To send something just add the following line, in whcih the first parameter of the method PutWorkspaceData is the matlab variable that will be created, the second one is the type of variable (can be added to the base space or to the global space), and the last one is the name in of the variable in DELPHI. name:='MyFileNameWithNumericalData.txt'; MatApp.PutWorkspaceData('File_Arff','base', name);

http://www.codeproject.com/useritems/MatlabDelphiCOM.asp

Finally, to execute use the method Execute, the only parameter needed is the string with the command required. MatApp.Execute('A=load('File_Arff');'); MatApp.Execute('plot(A)');

About Corzo
Civil Engineer ECI Msc. Hydroinformatics UNESCO-IHE Delft(Holland) Actually Research Fellow

http://www.codeproject.com/useritems/MatlabDelphiCOM.asp

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy