In comp.soft-sys.ptolemy, [EMAIL PROTECTED] (Project Group) posted three messages concerning Ptolemy and Matlab.
I've combined those messages into this message. > Subject: Ptolemy && matlab > Hi, we would like to use the matlab code to enhance the simulation > result in the vergil. Sounds interesting. > We have set the run enviroment by following the > web's instruction. And the test > "$PTII/ptolemy/matlab/demo/MatlabExpression/MatlabExpression.xml" also > successfully run. > > Our problem is: Is there any API for the use of this interface? We > are not sure the way of linking matlab and Ptolemy actor- > MatlabExpression. Ptolemy II 2.0.1 contains an interface to Matlab written by Zoltan Kemenczy and others at Research In Motion, Ltd. The Ptolemy II/Matlab interface uses the Java Native Interface (JNI) to pass values from Java to the C based Matlab dynamic library. See $PTII/ptolemy/matlab/Engine.java for details about the API. Online, the source can be found at http://ptolemy.eecs.berkeley.edu/ptolemyII/ptII2.0/ptII2.0.1/ptolemy/matlab/Engine.java) and the javadoc output at http://ptolemy.eecs.berkeley.edu/ptolemyII/ptII2.0/ptII2.0.1/doc/codeDoc/ptolemy/matlab/package-summary.html The second message was > Subject: how can the Actor-- MatlabExpression link to a matlab .m file???? > How can we configure the MatlabExpression Actor so as to link a > matlab m file? > Also how to configure the directory/path of the m file?? > Subject: Ptolemy and Matlab > From the previous message, "So, you could develop m-files in Matlab > and then call that code from a Ptolemy actor." I would like to know, > what are the steps of executing this actor?? [Info from my earlier post about Matlab, where I [cxh] say:] > > > So, you could develop m-files in Matlab and then call that code > > from a Ptolemy actor. I had not actually developed a m-file and called it using the Matlab interface, but it can be done. http://ptolemy.eecs.berkeley.edu/ptolemyII/ptII2.0/ptII2.0.1/ptolemy/matlab/Expression.java says: A Parameter named <i>packageDirectories</i> may be added to this actor to augment the matlab engine's search path during the firing of this actor. The value of this parameter should evaluate to a StringToken, e.g.: <pre> "path1, path2, ..." </pre> containing a comma-separated list of paths to be prepended to the matlab engine search path before <i>expression</i> is evaluated. The list may contain paths relative to the directory in which ptolemy was started, or any directory listed in the current classpath (in that order, first match wins). See {@link ptolemy.data.expr.UtilityFunctions#findFile(String)}. After evaluation, the previous search path is restored.<p> This suggests that by adding a packageDirectories parameter, we can cause Matlab to search in our directories for our m-file. I was able to do this by creating a simple SDF model that looks like: Ramp->ptolemy.matlab.Expression->Display I first added a port called input to the Expression actor and set the expression to output=input; and verified that everything worked I then added a packageDirectories parameter to ptolemy.matlab.Expression actor by double clicking on the actor and adding the parameter Name: packageDirectories Default value: Class: ptolemy.data.expr.Parameter I changed the value of the expression and the packageDirectories to expression: output=mFileTest(input); packageDirectories: "c:/cxh" I then created c:/cxh/mFileTest.m that contains: function t = mFileTest(varargin) t=varargin{1} * 3.0; When I run the model, my mFileTest.m is found and the mFileTest function is found in it and the input is multiplied by 3.0 Note that I have very little experience using Matlab, so there are probably bettery ways to do this. The Ptolemy II 2.0.1 model I used is below: <?xml version="1.0" standalone="no"?> <!DOCTYPE entity PUBLIC "-//UC Berkeley//DTD MoML 1//EN" "http://ptolemy.eecs.berkeley.edu/xml/dtd/MoML_1.dtd"> <entity name="mFileTest" class="ptolemy.actor.TypedCompositeActor"> <property name="_createdBy" class="ptolemy.kernel.util.VersionAttribute" value="2.0.1"> </property> <property name="_vergilSize" class="ptolemy.actor.gui.SizeAttribute" value="[600, 400]"> </property> <property name="_vergilLocation" class="ptolemy.actor.gui.LocationAttribute" value="[104, 126]"> </property> <property name="SDF Director" class="ptolemy.domains.sdf.kernel.SDFDirector"> <property name="Scheduler" class="ptolemy.domains.sdf.kernel.SDFScheduler"> </property> <property name="iterations" class="ptolemy.data.expr.Parameter" value="5"> </property> <property name="vectorizationFactor" class="ptolemy.data.expr.Parameter" value="1"> </property> <property name="_location" class="ptolemy.moml.Location" value="75.0, 45.0"> </property> </property> <entity name="Ramp" class="ptolemy.actor.lib.Ramp"> <property name="firingCountLimit" class="ptolemy.data.expr.Parameter" value="0"> </property> <property name="init" class="ptolemy.data.expr.Parameter" value="0"> </property> <property name="step" class="ptolemy.data.expr.Parameter" value="1"> </property> <doc>Create a sequence of tokens with increasing value</doc> <property name="_location" class="ptolemy.moml.Location" value="95.0, 185.0"> </property> <port name="output" class="ptolemy.actor.TypedIOPort"> <property name="output"/> </port> <port name="trigger" class="ptolemy.actor.TypedIOPort"> <property name="input"/> <property name="multiport"/> </port> </entity> <entity name="MatlabExpression" class="ptolemy.matlab.Expression"> <property name="expression" class="ptolemy.kernel.util.StringAttribute" value="output=mFileTest(input);"> </property> <property name="_icon" class="ptolemy.vergil.icon.BoxedValueIcon"> <property name="attributeName" class="ptolemy.kernel.util.StringAttribute" value="expression"> </property> <property name="displayWidth" class="ptolemy.data.expr.Parameter" value="60"> </property> </property> <property name="_location" class="ptolemy.moml.Location" value="215.0, 185.0"> </property> <property name="packageDirectories" class="ptolemy.data.expr.Parameter" value=""c:/cxh""> </property> <port name="output" class="ptolemy.actor.TypedIOPort"> <property name="output"/> <property name="_type" class="ptolemy.actor.TypeAttribute" value="int"> </property> </port> <port name="input" class="ptolemy.actor.TypedIOPort"> <property name="input"/> <property name="_type" class="ptolemy.actor.TypeAttribute" value="int"> </property> </port> </entity> <entity name="Display" class="ptolemy.actor.lib.gui.Display"> <property name="rowsDisplayed" class="ptolemy.data.expr.Parameter" value="10"> </property> <property name="columnsDisplayed" class="ptolemy.data.expr.Parameter" value="40"> </property> <property name="title" class="ptolemy.kernel.util.StringAttribute"> </property> <property name="_location" class="ptolemy.moml.Location" value="400.0, 185.0"> </property> <port name="input" class="ptolemy.actor.TypedIOPort"> <property name="input"/> <property name="multiport"/> </port> </entity> <relation name="relation2" class="ptolemy.actor.TypedIORelation"> </relation> <relation name="relation" class="ptolemy.actor.TypedIORelation"> </relation> <link port="Ramp.output" relation="relation2"/> <link port="MatlabExpression.output" relation="relation"/> <link port="MatlabExpression.input" relation="relation2"/> <link port="Display.input" relation="relation"/> </entity> BTW - We modified the Ptolemy II FAQ http://ptolemy.eecs.berkeley.edu/ptolemyII/ptIIfaq.htm#simulink says: 1.3 How are Ptolemy II and Matlab/Simulink different? Ptolemy II has very little in common with Matlab, which is a textual, imperative, interactive, scientific programming language. Ptolemy II works with Matlab, thanks to an interface developed by Zoltan Kemenczy and others at Research In Motion, Ltd. See http://ptolemy.eecs.berkeley.edu/ptolemyII/ptIIlatest/ptII/ptolemy/matlab/matlab.htm Ptolemy II has much more in common with Simulink, which is a graphical block-diagram language, originally developed for control system design. Simulink has a rich and expressive model of computation with continuous-time semantics and support for periodic discrete-time signals. Some of its principles have been incorporated in the CT (continuous-time) domain of Ptolemy II, but not all. The CT domain, for example, does not have the notion of "sample time" (which in Simulink provides the periodic discrete-time support) nor the support for algebraic loops. There is also currently no code generation support in CT (in Simulink, this is provided through the associated product Real-Time Workshop). Also, the CT domain has implemented fewer ODE solvers than those provided by Simulink and has a smaller actor library. Ptolemy II and Simulink both support extension of the actor library through well-defined interfaces (in Simulink, this is called the S-function interface). However, Ptolemy II is a more open architecture in that its infrastructure is open source, and the interfaces to the core mechanisms in the software are published and documented. The persistent file format (MoML) is XML in Ptolemy II, which makes it both more verbose and more portable than the Simulink syntax (MDL files). Simulink supports one model of computation, whereas Ptolemy II supports several, and can be extended with new models of computation. Simulink can also be extended, as for example it has been with the associated product Stateflow, which supports state-machine modeling. But in Simulink, the extension is done by defining new blocks using the S-function interface. As such, additional models of computation added this way are second class. For example, they cannot define the model of computation at the top level of the hierarchy, and cannot contain Simulink models within their own components. -Christopher Christopher Hylands [EMAIL PROTECTED] University of California Programmer/Analyst Chess/Ptolemy/GSRC US Mail: 558 Cory Hall #1770 ph: (510)643-9841 fax:(510)642-2739 Berkeley, CA 94720-1770 home: (510)526-4010, (707)665-0131 (office: 400A Cory) ---------------------------------------------------------------------------- Posted to the ptolemy-hackers mailing list. Please send administrative mail for this list to: [EMAIL PROTECTED]