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

  • Pobierz
  • Dodaj do moich podręczników
  • Drukuj
  • Strona
    / 292
  • Spis treści
  • BOOKMARKI
  • Oceniono. / 5. Na podstawie oceny klientów
Przeglądanie stron 52
Passing Arguments to and from Java
Code Fragment: Passing an MWArray. This example constructs an
MWNumericArray of type MWClassID.DOUBLE.Thecalltomyprimes passes the
number of outputs,
1,andtheMWNumericArray, x:
x = new MWNumericArray(n, MWClassID.DOUBLE);
cls = new myclass();
y = cls.myprimes(1, x);
Java Builder converts the MWNumericArray object to a MATLAB scalar double
to pass to the M-function.
Automatic Conversion to a MATLAB Type
When passing an argument only a small number of times, it is usually just
as eff ici ent to pass a primitiv e Java type or object. In this case, the calling
mechanism converts the data for you into an equivalent MATLAB type.
For instance, e ither of the following Java types w ould be autom atically
converted to the MATLAB
double type:
AJava
double primitive
An object of class
java.lang.Double
For reference information about data conversion (tables showing each Java
type along with its converted MATLAB type, and each MATLAB type with its
converted Java type), see “D ata Co nv ersion R ules” o n page 6 -10.
Code Fragment: Automatic Data Conversion
When ca ll ing the makesqr method used in the getmagic application, you could
construct an object of type
MWNumericArray. Doing so would be an example
of manual conversion. Instead, y ou could rely on automatic conversion, as
shown in the following code fragment:
result = M.makesqr(1, arg[0]);
In this case, a Java double is passed as arg[0].
3-7
Przeglądanie stron 52
1 2 ... 48 49 50 51 52 53 54 55 56 57 58 ... 291 292

Komentarze do niniejszej Instrukcji

Brak uwag