/** * Gets two-dimensional real array. * * @return - 2D real array */ public byte[][] getArray() { byte[][] result = new byte[getM()][]; for (int m = 0; m < getM(); m++) { result[m] = new byte[getN()]; for (int n = 0; n < getN(); n++) { result[m][n] = get(m, n); } } return result; }
@Test public void testUInt8() throws Exception { String fileName = "uint8.mat"; String arrName = "arr"; MatFileReader mfr; MLArray src; // read array form file mfr = new MatFileReader(getTestFile(fileName)); assertEquals("Test min. value from file:" + fileName + " array: " + arrName, (byte) 0, (byte) ((MLUInt8) mfr.getMLArray(arrName)).get(0, 0), 0.001); assertEquals("Test max. value from file:" + fileName + " array: " + arrName, (byte) 255, (byte) ((MLUInt8) mfr.getMLArray(arrName)).get(0, 1), 0.001); src = mfr.getMLArray(arrName); // write fileName = "uint8out.mat"; ArrayList<MLArray> towrite = new ArrayList<MLArray>(); towrite.add(mfr.getMLArray(arrName)); new MatFileWriter(getTempFile(fileName), towrite); // read again mfr = new MatFileReader(getTempFile(fileName)); assertEquals("Test min. value from file:" + fileName + " array: " + arrName, (byte) 0, (byte) ((MLUInt8) mfr.getMLArray(arrName)).get(0, 0), 0.001); assertEquals("Test max. value from file:" + fileName + " array: " + arrName, (byte) 255, (byte) ((MLUInt8) mfr.getMLArray(arrName)).get(0, 1), 0.001); assertEquals("Test if array retrieved from " + fileName + " equals source array", src, mfr.getMLArray(arrName)); }
/** * Gets two-dimensional real array. * * @return - 2D real array */ public byte[][] getArray() { byte[][] result = new byte[getM()][]; for (int m = 0; m < getM(); m++) { result[m] = new byte[getN()]; for (int n = 0; n < getN(); n++) { result[m][n] = get(m, n); } } return result; }