On Mon, Apr 4, 2011 at 7:21 PM, bzink <william.z...@juno.com> wrote: > Hello, Could someone who is familiar with the Java package explain how to > pass a 2D octave array to a java method? > > When I try the following java method > > package naa.tools; > public class Matlab > { > static public String isa(double [][] x) { return "double [][]";} > static public String isa(Object x) {return x.getClass().getName();} > } > > on the octave command-line with a 2D matrix, I get, for example, > > octave-3.2.4.exe:4> java_invoke("naa.tools.Matlab", "isa", [1 2; 3 4]) > ans = org.octave.OctaveReference > > So if a 2D octave matrix does not map directly to a java double [][], is > there a method to test whether this OctaveReference object refers to a > matrix, and if so, to convert that reference to a double[][] version of the > original argument? > > I use java-1.2.7 on the Octave-Forge Windows v3.2.4 binary.
You can't do much with an OctaveReference object. This was only a way to pass octave objects to Java such that they can be passed back to octave from Java. By default, the java module will only convert one-dimensional matrices (row or column vector) into double[] objects. However, other conversions are available when setting the java_convert_matrix variable to 1, as in java_convert_matrix(1) That function returns the previous value of the internal flag, such that you can write: flag = java_convert_matrix(1) unwind_protect # do something unwind_protect_cleanup java_convert_matrix(flag) end_unwind_protect When this flag is set, octave matrices will be converted to org.octave.Matrix objects. That class provides some basic functionalities, such as the method "asDoubleMatrix()" which converts the Matrix object into double[][], provided that the matrix is 2D. Note also that Matrix objects will also be automatically converted to equivalent octave matrices when returning back to octave world. The java->octave matrix conversion is also controlled by the java_unsigned_conversion flag (similar syntax as java_convert_matrix). When this flag is set, Matrix objects whose internal data array is byte[] or int[] will be converted into uint8 and uint32 octave matrices. Otherwise, they will be converted into int8 and int32 matrices. If you want more information about the Matrix class, see the source code in http://octave.svn.sourceforge.net/viewvc/octave/trunk/octave-forge/extra/java/src/org/octave/Matrix.java?revision=HEAD&view=markup Hope this helps. Michael. ------------------------------------------------------------------------------ Xperia(TM) PLAY It's a major breakthrough. An authentic gaming smartphone on the nation's most reliable network. And it wants your games. http://p.sf.net/sfu/verizon-sfdev _______________________________________________ Octave-dev mailing list Octave-dev@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/octave-dev