MATLAB BUILDER JA 2 Podręcznik Użytkownika Strona 52

  • Pobierz
  • Dodaj do moich podręczników
  • Drukuj
  • Strona
    / 292
  • Spis treści
  • BOOKMARKI
  • Oceniono. / 5. Na podstawie oceny klientów
Przeglądanie stron 51
3 Programming
Passing Argum ents to and from Java
When you invoke a method on a MATLAB Builder for Java component,
the input arguments received by the method must be in the MATLAB
internal array format. You can either conv ert them yourself w ithin the
calling program, or pass the arguments as Java d ata types, which are then
automatically converted by the calling mechanism.
To convert them yourself, use instances of the
MWArray classes; in this case
you are using manual conversion. Storing your data using the classes and
data types defined in the Java langu age means that you are relying on
automatic conversion. Most likely, you will use a combination of manual and
automatic conversion.
“Manual C onversion of Data Types” on page 3-6
“Auto matic Conversion to a MATLAB Type” on page 3-7
“Specifying Optional Arguments” on page 3-9
“Handling Return Values” on page 3-14
Manual Conversion of Data Types
To manually convert to one of the standard MATLAB data types, use the
MWArray data conv ersion classes provided by Java Builder. For class reference
information, see the
com.mathworks.toolbox.javabuilder package. For
extensive usage inf orm ation, see Chapter 4, “Using MWArray Classes”.
Code Fragment: Using MWNumericArray
The getmagic example shows manual conversion. The following code
fragment from that program shows a
java.lang.Double argument that is
converted to an
MWNumericArray type that can be used by the M-function
without further conversion.
MWNumericArray dims = null;
dims = new MWNumericArray(Double.valueOf(args[0]),
MWClassID.DOUBLE);
result = theMagic.makesqr(1, dims);
3-6
Przeglądanie stron 51
1 2 ... 47 48 49 50 51 52 53 54 55 56 57 ... 291 292

Komentarze do niniejszej Instrukcji

Brak uwag