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

  • Pobierz
  • Dodaj do moich podręczników
  • Drukuj
  • Strona
    / 292
  • Spis treści
  • BOOKMARKI
  • Oceniono. / 5. Na podstawie oceny klientów
Przeglądanie stron 73
3 Programming
Handling Data Conversion Between Java and MATLAB
The call signature for a method that encapsulates a MATLAB function uses
one of the MATLAB data conve rsio n classes to pass arguments and return
output. When you call any such method, all input arguments not derived
from one of the
MWArray classes a re converted by Java Builder to the correct
MWArray type before being passed to the MATLAB method.
For example, consider the following Java statement:
result = theFourier.plotfft(3, data, new Double(interval));
The third argument is of type java.lang.Double, which converts to a
MATLAB 1-by-1
double array.
Calling MWArray Methods
The conversio n rul es ap pl y no t only when calling your own methods, but
also when calling constructors and factory methods belonging to the
MWArray
classes. For examp l e, the following code calls the constructor for t he
MWNumericArray class with a Java double input. Java Build er con verts
the Java
double input to an instance of MWNumericArray having a ClassID
property of MWClassID.DOUBLE. This is the equivalent of a MATLAB 1-by-1
double array.
double Adata = 24;
MWNumericArray A = new MWnumericArray(Adata);
System.out.println("Array A is of type " + A.classID());
When you run this example, the results are as follows:
Array A is of type double
Specifying the Type
There is an exception: if you supply a specific data type in the same
constructor, Java Builder converts to that type rather than following the
default con vers ion rules. Here, the code specifies that
A should be constructed
as a MATLAB 1-by-1 16-bit integer array:
double Adata = 24;
3-28
Przeglądanie stron 73
1 2 ... 69 70 71 72 73 74 75 76 77 78 79 ... 291 292

Komentarze do niniejszej Instrukcji

Brak uwag