User`s guide

Using Class Methods
Example Setting Values in a Structure Array
int[] sdims = {1, 2};
String[] sfields = {"f1", "f2", "f3"};
MWStructArray S = new MWStructArray(sdims, sfields);
Integer[] val = new Integer[25];
for(inti=0;i<6;i++)
val[i] = new Integer(i * 15);
for(inti=0;i<2;i++)
for (int j = 0; j < sfields.length; j++)
S.set(sfields[j], i+1, val[j + (i * 3)]);
// Use getData to get data from the structure.
System.out.println("Data read from structure array S: \n");
Object[] x = (Object[]) S.getData();
for (int i = 0; i < x.length; i++)
System.out.print(" " + ((int[][]) x[i])[0][0]);
When run, the example displays this output:
Data read from structure array S:
01530456075
toArray. This method returns an array containing a copy of the data in t h e
underlying MATLAB array.
The prototype for the
toArray method is
public Object[] toArray()
toArray
returns an array with the same dim ensionality as the MATLAB
array. Before converting, a new array is derived by transforming the struct
array into a cell array such that an N-by-M-by-... struct array w ith P fields
is transformed into a P-by-N-by-M-by-... cell array. Each element in the
returned array is converted to a Java a rray when you call
MWArray.toArray()
on the corresponding cell.
4-131