MATLAB External Interfaces

2y ago
17 Views
2 Downloads
3.55 MB
832 Pages
Last View : 7d ago
Last Download : 3m ago
Upload by : Rosa Marty
Transcription

MATLAB External InterfacesR2011b

How to Contact MathWorksWebNewsgroupwww.mathworks.com/contact TS.html Technical service@mathworks.cominfo@mathworks.comProduct enhancement suggestionsBug reportsDocumentation error reportsOrder status, license renewals, passcodesSales, pricing, and general information508-647-7000 (Phone)508-647-7001 (Fax)The MathWorks, Inc.3 Apple Hill DriveNatick, MA 01760-2098For contact information about worldwide offices, see the MathWorks Web site.MATLAB External Interfaces COPYRIGHT 1984–2011 by The MathWorks, Inc.The software described in this document is furnished under a license agreement. The software may be usedor copied only under the terms of the license agreement. No part of this manual may be photocopied orreproduced in any form without prior written consent from The MathWorks, Inc.FEDERAL ACQUISITION: This provision applies to all acquisitions of the Program and Documentationby, for, or through the federal government of the United States. By accepting delivery of the Programor Documentation, the government hereby agrees that this software or documentation qualifies ascommercial computer software or commercial computer software documentation as such terms are usedor defined in FAR 12.212, DFARS Part 227.72, and DFARS 252.227-7014. Accordingly, the terms andconditions of this Agreement and only those rights specified in this Agreement, shall pertain to and governthe use, modification, reproduction, release, performance, display, and disclosure of the Program andDocumentation by the federal government (or other entity acquiring for or through the federal government)and shall supersede any conflicting contractual terms or conditions. If this License fails to meet thegovernment’s needs or is inconsistent in any respect with federal procurement law, the government agreesto return the Program and Documentation, unused, to The MathWorks, Inc.TrademarksMATLAB and Simulink are registered trademarks of The MathWorks, Inc. Seewww.mathworks.com/trademarks for a list of additional trademarks. Other product or brandnames may be trademarks or registered trademarks of their respective holders.PatentsMathWorks products are protected by one or more U.S. patents. Please seewww.mathworks.com/patents for more information.

Revision HistoryDecember 1996July 1997January 1998October 1998November 2000June 2001July 2002January 2003June 2004October 2004September 2005March 2006September 2006March 2007September 2007March 2008October 2008March 2009September 2009March 2010September 2010April 2011September 2011First printingOnline onlySecond printingThird printingFourth printingOnline onlyOnline onlyOnline onlyOnline onlyOnline onlyOnline onlyOnline onlyOnline onlyOnline onlyOnline onlyOnline onlyOnline onlyOnline onlyOnline onlyOnline onlyOnline onlyOnline onlyOnline onlyNew for MATLAB 5 (release 8)Revised for MATLAB 5.1 (Release 9)Revised for MATLAB 5.2 (Release 10)Revised for MATLAB 5.3 (Release 11)Revised and renamed for MATLAB 6.0 (Release 12)Revised for MATLAB 6.1 (Release 12.1)Revised for MATLAB 6.5 (Release 13)Revised for MATLAB 6.5.1 (Release 13SP1)Revised for MATLAB 7.0 (Release 14)Revised for MATLAB 7.0.1 (Release 14SP1)Revised for MATLAB 7.1 (Release 14SP3)Revised for MATLAB 7.2 (Release 2006a)Revised for MATLAB 7.3 (Release 2006b)Revised for MATLAB 7.4 (Release 2007a)Revised for MATLAB 7.5 (Release 2007b)Revised for MATLAB 7.6 (Release 2008a)Revised for MATLAB 7.7 (Release 2008b)Revised for MATLAB 7.8 (Release 2009a)Revised for MATLAB 7.9 (Release 2009b)Revised for MATLAB 7.10 (Release 2010a)Revised for MATLAB 7.11 (Release 2010b)Revised for MATLAB 7.12 (Release 2011a)Revised for MATLAB 7.13 (Release 2011b)

ContentsRead and Write MATLAB MAT-Files in C/C and Fortran1Custom Applications to Read and Write MAT-Files . . .Why Write Custom Applications? . . . . . . . . . . . . . . . . . . . .What You Need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .MAT-File Interface Library . . . . . . . . . . . . . . . . . . . . . . . . .Finding Associated Files . . . . . . . . . . . . . . . . . . . . . . . . . . . .Exchanging Data Files Between Platforms . . . . . . . . . . . . .1-21-21-31-41-51-6Copying External Data into MAT-File Format withStandalone Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . .Overview of matimport.c Example . . . . . . . . . . . . . . . . . . . .Declare Variables for External Data . . . . . . . . . . . . . . . . . .Create mxArray Variables . . . . . . . . . . . . . . . . . . . . . . . . . .Create MATLAB Variable Names . . . . . . . . . . . . . . . . . . . .Read External Data into mxArray Data . . . . . . . . . . . . . . .Create and Open MAT-File . . . . . . . . . . . . . . . . . . . . . . . . .Write mxArray Data to File . . . . . . . . . . . . . . . . . . . . . . . . .Clean Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Build the Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Create the MAT-File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Import Data into MATLAB . . . . . . . . . . . . . . . . . . . . . . . . ples of MAT-File Applications . . . . . . . . . . . . . . . . .List of Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Creating a MAT-File in C . . . . . . . . . . . . . . . . . . . . . . . . . . .Creating a MAT-File in C . . . . . . . . . . . . . . . . . . . . . . . . .Reading a MAT-File in C/C . . . . . . . . . . . . . . . . . . . . . . .Creating a MAT-File in Fortran . . . . . . . . . . . . . . . . . . . . . .Reading a MAT-File in Fortran . . . . . . . . . . . . . . . . . . . . . .1-131-131-141-141-141-151-16Compiling and Linking MAT-File Programs . . . . . . . . . .Building on UNIX Operating Systems . . . . . . . . . . . . . . . . .Building on Windows Operating Systems . . . . . . . . . . . . . .Deploying MAT-File Applications . . . . . . . . . . . . . . . . . . . .1-171-171-191-19v

Calling C Shared Library Functions fromMATLAB2viContentsCalling Functions in Shared Libraries . . . . . . . . . . . . . . .What Is a Shared Library? . . . . . . . . . . . . . . . . . . . . . . . . . .Selecting a Compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Loading the Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Unloading the Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Viewing Library Functions . . . . . . . . . . . . . . . . . . . . . . . . . .Invoking Library Functions . . . . . . . . . . . . . . . . . . . . . . . . .Limitations to Shared Library Support . . . . . . . . . . . . . . . .Troubleshooting Shared Library Applications . . . . . . . . . .2-22-22-32-32-42-42-72-82-12Passing Arguments to Shared Library Functions . . . . .C and MATLAB Equivalent Types . . . . . . . . . . . . . . . . . . . .Passing Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Examples of Passing Data to Shared Libraries . . . . . . . . . .Passing Pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Passing a NULL Pointer . . . . . . . . . . . . . . . . . . . . . . . . . . . .Manually Converting Data Passed to Functions . . . . . . . . .2-132-132-152-162-222-232-23Working with Pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . .The libpointer Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Constructing a libpointer Object . . . . . . . . . . . . . . . . . . . . .Reading a libpointer Object . . . . . . . . . . . . . . . . . . . . . . . . .Creating a Pointer to a Primitive Type . . . . . . . . . . . . . . . .Creating a Pointer to a Structure . . . . . . . . . . . . . . . . . . . .Passing a Pointer to the First Element of an Array . . . . . .Putting a String into a Void Pointer . . . . . . . . . . . . . . . . . .Passing an Array of Strings . . . . . . . . . . . . . . . . . . . . . . . . .Memory Allocation for an External Library . . . . . . . . . . . .Multilevel Pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ng with Structures . . . . . . . . . . . . . . . . . . . . . . . . . . .Structure Argument Requirements . . . . . . . . . . . . . . . . . . .Working with Structures Examples . . . . . . . . . . . . . . . . . . .Finding Structure Field Names . . . . . . . . . . . . . . . . . . . . . .Example of Passing a MATLAB Structure . . . . . . . . . . . . .Passing a libstruct Object . . . . . . . . . . . . . . . . . . . . . . . . . . .Using the Structure as an Object . . . . . . . . . . . . . . . . . . . . .2-392-392-392-402-412-412-44

Creating C/C and Fortran Programs to beCallable from MATLAB (MEX-Files)3Introducing MEX-Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . .What Are MEX-Files? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Definition of MEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .MEX and MX Matrix Libraries . . . . . . . . . . . . . . . . . . . . . .Introduction to Source MEX-Files . . . . . . . . . . . . . . . . . . . .Overview of Creating a Binary MEX-File . . . . . . . . . . . . . .Configuring Your Environment . . . . . . . . . . . . . . . . . . . . . .3-23-23-33-33-33-43-4Using MEX-Files to Call C/C and FortranPrograms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Creating a Source MEX-File . . . . . . . . . . . . . . . . . . . . . . . . .Workflow of a MEX-File . . . . . . . . . . . . . . . . . . . . . . . . . . . .Using Binary MEX-Files . . . . . . . . . . . . . . . . . . . . . . . . . . . .Binary MEX-File Placement . . . . . . . . . . . . . . . . . . . . . . . . .Using Help Files with MEX-Files . . . . . . . . . . . . . . . . . . . .Workspace for MEX-File Functions . . . . . . . . . . . . . . . . . . .3-53-53-103-153-163-163-17MATLAB Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .The MATLAB Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Data Storage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .MATLAB Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Sparse Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Using Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-183-183-183-203-213-22Building MEX-Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .What You Need to Build MEX-Files . . . . . . . . . . . . . . . . . .Selecting a Compiler on Windows Platforms . . . . . . . . . . . .Selecting a Compiler on UNIX Platforms . . . . . . . . . . . . . .Linking Multiple Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Overview of Building the timestwo MEX-File . . . . . . . . . . .3-243-243-243-303-333-33Table of MEX Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-35Troubleshooting MEX-Files . . . . . . . . . . . . . . . . . . . . . . . . .Technical Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Configuration Issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Understanding MEX-File Problems . . . . . . . . . . . . . . . . . . .3-403-403-403-43vii

Compiler and Platform-Specific Issues . . . . . . . . . . . . . . . .Memory Management Issues . . . . . . . . . . . . . . . . . . . . . . . .3-473-48Custom Building MEX-Files . . . . . . . . . . . . . . . . . . . . . . . .Who Should Read This Chapter . . . . . . . . . . . . . . . . . . . . . .MEX Script Switches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Custom Building on UNIX Systems . . . . . . . . . . . . . . . . . . .Custom Building on Windows Systems . . . . . . . . . . . . . . . .3-543-543-543-583-62Calling LAPACK and BLAS Functions fromMEX-Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .What You Need to Know . . . . . . . . . . . . . . . . . . . . . . . . . . . .Creating a MEX-File Using LAPACK and BLASFunctions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Preserving Input Values from Modification . . . . . . . . . . . .Passing Arguments to Fortran Functions from C/C Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Passing Arguments to Fortran Functions from FortranPrograms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Handling Complex Numbers in LAPACK and BLASFunctions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Modifying the Function Name on UNIX Systems . . . . . . . .3-703-703-713-733-743-753-763-80Running MEX-Files with .DLL File Extensions onWindows 32-bit Platforms . . . . . . . . . . . . . . . . . . . . . . . .3-81Upgrading MEX-Files to Use 64-Bit API . . . . . . . . . . . . . .MATLAB Support for 64-Bit Indexing . . . . . . . . . . . . . . . . .MEX Uses 32-Bit API by Default . . . . . . . . . . . . . . . . . . . . .What If I Do Not Upgrade? . . . . . . . . . . . . . . . . . . . . . . . . . .How to Upgrade MEX-Files to Use the 64-Bit API . . . . . . .3-823-823-823-843-86Creating C/C Language MEX-Files4C/C Source MEX-Files . . . . . . . . . . . . . . . . . . . . . . . . . . . .The Components of a C/C MEX-File . . . . . . . . . . . . . . . .Gateway Routine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Computational Routine . . . . . . . . . . . . . . . . . . . . . . . . . . . . .viiiContents4-24-24-24-5

Preprocessor Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Data Flow in MEX-Files . . . . . . . . . . . . . . . . . . . . . . . . . . . .Creating C MEX-Files . . . . . . . . . . . . . . . . . . . . . . . . . . .4-54-54-9Examples of C/C Source MEX-Files . . . . . . . . . . . . . . . .Introduction to C/C Examples . . . . . . . . . . . . . . . . . . . . .Passing a Scalar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Passing Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Passing Two or More Inputs or Outputs . . . . . . . . . . . . . . .Passing Structures and Cell Arrays . . . . . . . . . . . . . . . . . . .Filling an mxArray . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Prompting User for Input . . . . . . . . . . . . . . . . . . . . . . . . . . .Handling Complex Data . . . . . . . . . . . . . . . . . . . . . . . . . . . .Handling 8-, 16-, and 32-Bit Data . . . . . . . . . . . . . . . . . . . .Manipulating Multidimensional Numerical Arrays . . . . . .Handling Sparse Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . .Calling Functions from C/C MEX-Files . . . . . . . . . . . . . .Using C Features in MEX-Files . . . . . . . . . . . . . . . . . . . .File Handling with C . . . . . . . . . . . . . . . . . . . . . . . . . . . -224-234-24Debugging C/C Language MEX-Files . . . . . . . . . . . . . .Notes on Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Debugging on the Microsoft Windows Platforms . . . . . . . .Debugging on Linux Platforms . . . . . . . . . . . . . . . . . . . . . . .4-264-264-264-34Handling Large mxArrays . . . . . . . . . . . . . . . . . . . . . . . . . .Using the 64-Bit API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Building the Binary MEX-File . . . . . . . . . . . . . . . . . . . . . . .Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Caution Using Negative Values . . . . . . . . . . . . . . . . . . . . . .Building Cross-Platform Applications . . . . . . . . . . . . . . . . .4-374-374-394-394-404-40Memory Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Automatic Cleanup of Temporary Arrays . . . . . . . . . . . . . .Persistent Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Hybrid Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-414-414-424-43Large File I/O . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Prerequisites to Using 64-Bit I/O . . . . . . . . . . . . . . . . . . . . .Specifying Constant Literal Values . . . . . . . . . . . . . . . . . . .Opening a File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Printing Formatted Messages . . . . . . . . . . . . . . . . . . . . . . .4-454-454-474-484-49ix

Replacing fseek and ftell with 64-Bit Functions . . . . . . . . .Determining the Size of an Open File . . . . . . . . . . . . . . . . .Determining the Size of a Closed File . . . . . . . . . . . . . . . . .4-494-504-51Creating Fortran MEX-Files5xContentsFortran Source MEX-Files . . . . . . . . . . . . . . . . . . . . . . . . . .The Components of a Fortran MEX-File . . . . . . . . . . . . . . .Gateway Routine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Computational Routine . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Preprocessor Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Using the Fortran %val Construct . . . . . . . . . . . . . . . . . . . .Data Flow in MEX-Files . . . . . . . . . . . . . . . . . . . . . . . . . . . .5-25-25-25-55-55-65-7Examples of Fortran Source MEX-Files . . . . . . . . . . . . . .Introduction to Fortran Examples . . . . . . . . . . . . . . . . . . . .Passing a Scalar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Passing Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Passing Arrays of Strings . . . . . . . . . . . . . . . . . . . . . . . . . . .Passing Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Passing Integers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Passing Two or More Inputs or Outputs . . . . . . . . . . . . . . .Handling Complex Data . . . . . . . . . . . . . . . . . . . . . . . . . . . .Dynamically Allocating Memory . . . . . . . . . . . . . . . . . . . . .Handling Sparse Matrices . . . . . . . . . . . . . . . . . . . . . . . . . .Calling Functions from Fortran MEX-Files . . . . . . . . . . . ebugging Fortran Source MEX-Files . . . . . . . . . . . . . . .Notes on Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Debugging on Microsoft Windows Platforms . . . . . . . . . . . .Debugging on Linux Platforms . . . . . . . . . . . . . . . . . . . . . . .5-225-225-225-22Handling Large mxArrays . . . . . . . . . . . . . . . . . . . . . . . . . .Using the 64-Bit API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Building the Binary MEX-File . . . . . . . . . . . . . . . . . . . . . . .Caution Using Negative Values . . . . . . . . . . . . . . . . . . . . . .Building Cross-Platform Applications . . . . . . . . . . . . . . . . .5-265-265-285-285-28

Memory Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5-29Calling MATLAB Engine from C/C andFortran Programs6Using MATLAB Engine . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Introduction to MATLAB Engine . . . . . . . . . . . . . . . . . . . . .What You Need to Build Engine Applications . . . . . . . . . . .The Engine Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .GUI-Intensive Applications . . . . . . . . . . . . . . . . . . . . . . . . .6-26-26-36-46-5Examples of Calling Engine Functions . . . . . . . . . . . . . . .Examples Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Calling MATLAB Software from a C Application . . . . . . . .Calling MATLAB Software from a C Application . . . . . .Calling MATLAB Software from a Fortran Application . . .Attaching to an Existing MATLAB Session . . . . . . . . . . . .6-66-66-66-86-86-9Compiling Engine Applications with the MEXCommand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Requirements to Build and Run Engine Applications . . . .Building and Running Engine Applications on WindowsOperating Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Windows Engine Example engwindemo . . . . . . . . . . . . . . .Building and Running Engine Applications on UNIXOperating Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .UNIX Engine Example engdemo . . . . . . . . . . . . . . . . . . . . .6-116-116-126-146-156-16Compiling Engine Applications in an IDE . . . . . . . . . . . .Configuring the IDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Files Required by Engine Applications . . . . . . . . . . . . . . . .6-186-186-18Troubleshooting Engine Applications . . . . . . . . . . . . . . .Can’t Start MATLAB Engine Message . . . . . . . . . . . . . . . .Debugging MATLAB Functions Used in EngineApplications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6-226-226-22xi

Using Java Libraries from MATLAB7xiiContentsProduct Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Sun Java Interface Is Integral to MATLAB Software . . . .Benefits of the MATLAB Java Interface . . . . . . . . . . . . . . .Who Should Use the MATLAB Java Interface . . . . . . . . . .To Learn More About Java Programming Language . . . . .Platform Support for JVM Software . . . . . . . . . . . . . . . . . .Using a Different Version of JVM Software . . . . . . . . . . . .7-27-27-27-27-37-37-3Bringing Java Classes and Methods into MATLABWorkspace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Sources of Java Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . .Defining New Java Classes . . . . . . . . . . . . . . . . . . . . . . . . .The Java Class Path . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Making Java Classes Available in MATLAB Workspace . .Loading Java Class Definitions . . . . . . . . . . . . . . . . . . . . . .Simplifying Java Class Names . . . . . . . . . . . . . . . . . . . . . . .Locating Native Method Libraries . . . . . . . . . . . . . . . . . . . .Java Classes Contained in a JAR File . . . . . . . . . . . . . . . . .7-67-67-67-77-77-107-127-127-147-14Creating and Using Java Objects . . . . . . . . . . . . . . . . . . . .Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Constructing Java Objects . . . . . . . . . . . . . . . . . . . . . . . . . .Concatenating Java Objects . . . . . . . . . . . . . . . . . . . . . . . . .Saving and Loading Java Objects to MAT-Files . . . . . . . . .Finding the Public Data Fields of an Object . . . . . . . . . . . .Accessing Private and Public Data . . . . . . . . . . . . . . . . . . .Determining the Class of an Object . . . . . . . . . . . . . . . . . . .7-167-167-167-197-207-217-227-23Invoking Methods on Java Objects . . . . . . . . . . . . . . . . . .Using Java and MATLAB Calling Syntax . . . . . . . . . . . . . .Invoking Static Methods on Java Classes . . . . . . . . . . . . . .Obtaining Information About Methods . . . . . . . . . . . . . . . .Java Methods That Affect MATLAB Commands . . . . . . . .How MATLAB Software Handles Undefined Methods . . . .How MATLAB Software Handles Java Exceptions . . . . . .Method Execution in MATLAB Software . . . . . . . . . . . . . .7-257-257-277-287-327-337-347-34

Working with Java Arrays . . . . . . . . . . . . . . . . . . . . . . . . . .Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .How MATLAB Software Represents the Java Array . . . . .Creating an Array of Objects in MATLAB Software . . . . . .Accessing Elements of a Java Array . . . . . . . . . . . . . . . . . .Assigning to a Java Array . . . . . . . . . . . . . . . . . . . . . . . . . .Concatenating Java Arrays . . . . . . . . . . . . . . . . . . . . . . . . .Creating a New Array Reference . . . . . . . . . . . . . . . . . . . . .Creating a Copy of a Java Array . . . . . . . . . . . . . . . . . . . . .7-357-357-357-407-427-467-497-507-51Passing Data to a Java Method . . . . . . . . . . . . . . . . . . . . .Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Conversion of MATLAB Argument Data . . . . . . . . . . . . . . .Passing Built-In Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Passing String Arguments . . . . . . . . . . . . . . . . . . . . . . . . . .Passing Java Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Other Data Conversion Topics . . . . . . . . . . . . . . . . . . . . . . .Passing Data to Overloaded Methods . . . . . . . . . . . . . . . . .7-537-537-537-557-567-577-607-61Handling Data Returned from a Java Method . . . . . . . .Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Conversion of Java Return Types . . . . . . . . . . . . . . . . . . . .Built-In Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Java Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Converting Objects to MATLAB Types . . . . . . . . . . . . . . . .7-647-647-647-657-657-66Introduction to Programming Examples . . . . . . . . . . . . .7-71Example — Reading a URL . . . . . . . . . . . . . . . . . . . . . . . . .Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Description of URLdemo . . . . . . . . . . . . . . . . . . . . . . . . . . . .Running the Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-727-727-727-73Example — Finding an Internet Protocol Address . . . .Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Description of resolveip . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Running the Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7-757-757-757-76Example — Creating and Using a Phone Book . . . . . . . .Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Description of Function phonebook . . . . . . . . . . . . . . . . . . .7-777-777-78xiii

Description of Function pb lookup . . . . . . . . . . . . . . . . . . . .Description of Function pb add . . . . . . . . . . . . . . . . . . . . . .Description of Function pb remove . . . . . . . . . . . . . . . . . . .Description of Function pb change . . . . . . . . . . . . . . . . . . .Description of Function pb listall . . . . . . . . . . . . . . . . . . . .Description of Function pb display . . . . . . . . . . . . . . . . . . .Description of Function pb keyfilter . . . . . . . . . . . . . . . . . .Running the phonebook Program . . . . . . . . . . . . . . . . . . . . .7-827-837-847-857-867-877-877-88Using .NET Libraries from MATLAB8xivContentsOverview Using .NET from MATLAB . . . . . . . . . . . . . . . .What Is the Microsoft .NET Framework? . . . . . . . . . . . . . .Benefits of the MATLAB .NET Interface . . . . . . . . . . . . . . .Why Use the MATLAB .NET Interface? . . . . . . . . . . . . . . .Limitations to .NET Support . . . . . . . . . . . . . . . . . . . . . . . .What’s the Difference Between the MATLAB .NETInterface and MATLAB Builder NE? . . . . . . . . . . . . . . .System Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Using a .NET assembly in MATLAB . . . . . . . . . . . . . . . . . .To Learn More About the .NET Framework . . . . . . . . . . . .8-28-28-28-28-3Getting Started with .NET . . . . . . . . . . . . . . . . . . . . . . . . . .What is an Assembly? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .NET Terminology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Simplifying .NET Class Names . . . . . . . . . . . . . . . . . . . . . .Loading .NET Assemblies into MATLAB . . . . . . . . . . . . . .Handling Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Working With Nested Classes . . . . . . . . . . . . . . . . . . . . . . .8-78-78-88-98-108-108-10Using a .NET Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Creating a .NET Object . . . . . . . . . . . . . . . . . . . . . . . . . . . .Using netdoc.NetSample . . . . . . . . . . . . . . . . . . . . . . . . . . .What Classes Are in a .NET Assembly? . . . . . . . . . . . . . . .Using the delete Function on a .NET Object . . . . . . . . . . . .8-128-128-128-148-15Using .NET Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . .How MATLAB Represents .NET Properties . . . . . . . . . . . .8-168-168-48-58-58-6

How MATLAB Maps C# Property and Field AccessModifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8-17Using .NET Methods in MATLAB . . . . . . . . . . . . . . . . . . . .Calling .NET Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Call .NET Generic Methods . . . . . . . . . . . . . . . . . . . . . . . . .Call .NET Methods with Optional Arguments . . . . . . . . . .Calling .NET Extension Methods . . . . . . . . . . . . . . . . . . . . .Call .NET Properties That Take an Argument . . . . . . . . . .How MATLAB Represents .NET Operators . . . . . . . . . . . .Limitations to Support of .NET Methods . . . . . . . . . . . . . .8-188-188-208-208-228-238-248-25Working with .NET Events in MATLAB . . . . . . . . . . . . . .Use .NET Events in MATLAB . . . . . . . . . . . . . . . . . . . . . . .Limitations to Support of .NET Events . . . . . . . . . . . . . . . .8-268-268-27Handling .NET Data in MATLAB . . . . . . . . . . . . . . . . . . . .Passing Data to a .NET Object . . . . . . . . . . . . . . . . . . . . . . .Handling Data Returned from a .NET Object . . . . . . . . . . .8-288-288-34Using Arrays with .NET Applications . . . . . . . . . . . . . . . .Passing MATLAB Arrays to .NET

March 2008 Online only Revised for MATLAB 7.6 (Release 2008a) October 2008 Online only Revised for MATLAB 7.7 (Release 2008b) March 2009 Online only Revised for MATLAB 7.8 (Release 2009a) September 2009 Online only Revised for MATLAB 7.9 (Release 2009b) March 2010 Online only

Related Documents:

MATLAB tutorial . School of Engineering . Brown University . To prepare for HW1, do sections 1-11.6 – you can do the rest later as needed . 1. What is MATLAB 2. Starting MATLAB 3. Basic MATLAB windows 4. Using the MATLAB command window 5. MATLAB help 6. MATLAB ‘Live Scripts’ (for algebra, plotting, calculus, and solving differential .

19 MATLAB Excel Add-in Hadoop MATLAB Compiler Standalone Application MATLAB deployment targets MATLAB Compiler enables sharing MATLAB programs without integration programming MATLAB Compiler SDK provides implementation and platform flexibility for software developers MATLAB Production Server provides the most efficient development path for secure and scalable web and enterprise applications

MATLAB tutorial . School of Engineering . Brown University . To prepare for HW1, do sections 1-11.6 – you can do the rest later as needed . 1. What is MATLAB 2. Starting MATLAB 3. Basic MATLAB windows 4. Using the MATLAB command window 5. MATLAB help 6. MATLAB ‘Live Scripts’ (for

3. MATLAB script files 4. MATLAB arrays 5. MATLAB two‐dimensional and three‐dimensional plots 6. MATLAB used‐defined functions I 7. MATLAB relational operators, conditional statements, and selection structures I 8. MATLAB relational operators, conditional statements, and selection structures II 9. MATLAB loops 10. Summary

foundation of basic MATLAB applications in engineering problem solving, the book provides opportunities to explore advanced topics in application of MATLAB as a tool. An introduction to MATLAB basics is presented in Chapter 1. Chapter 1 also presents MATLAB commands. MATLAB is considered as the software of choice. MATLAB can be used .

I. Introduction to Programming Using MATLAB Chapter 1: Introduction to MATLAB 1.1 Getting into MATLAB 1.2 The MATLAB Desktop Environment 1.3 Variables and Assignment Statements 1.4 Expressions 1.5 Characters and Encoding 1.6 Vectors and Matrices Chapter 2: Introduction to MATLAB Programming 2.1 Algorithms 2.2 MATLAB Scripts 2.3 Input and Output

Compiler MATLAB Production Server Standalone Application MATLAB Compiler SDK Apps Files Custom Toolbox Python With MATLAB Users With People Who Do Not Have MATLAB.lib/.dll .exe . Pricing Risk Analytics Portfolio Optimization MATLAB Production Server MATLAB CompilerSDK Web Application

Lecture 14: MATLAB I “Official” Supported Version in CS4: MATLAB 2018a How to start using MATLAB: CS Dept. Machines - run ‘cs4_matlab’ Total Academic Handout (TAH) Local Install - software.brown.edu MATLAB Online (currently 2019a) - matlab.mathworks.com Navigating the Workspace (command window, variables, etc.) Data types in MATLAB (everything is a 64-bit .