• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java MatFileWriter类的典型用法和代码示例

java 4次浏览

本文整理汇总了Java中com.jmatio.io.MatFileWriter的典型用法代码示例。如果您正苦于以下问题:Java MatFileWriter类的具体用法?Java MatFileWriter怎么用?Java MatFileWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

MatFileWriter类属于com.jmatio.io包,在下文中一共展示了MatFileWriter类的24个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: writeSamplingNetworkData

点赞 3

import com.jmatio.io.MatFileWriter; //导入依赖的package包/类
public void writeSamplingNetworkData(SamplingNetworkData mcNetworkSamplingData) throws IOException {
    Objects.requireNonNull(mcNetworkSamplingData, "sampling network data is null");

    LOGGER.debug("Preparing buses mat data");
    MLStructure buses  = busesDataAsMLStructure(mcNetworkSamplingData.getBusesData());
    LOGGER.debug("Preparing generators mat data");
    MLStructure generators  = generatorsDataAsMLStructure(mcNetworkSamplingData.getGeneratorsData());
    LOGGER.debug("Preparing loads mat data");
    MLStructure loads  = loadsDataAsMLStructure(mcNetworkSamplingData.getLoadsData());
    LOGGER.debug("Saving mat data into " + matFile.toString());
    List<MLArray> mlarray = new ArrayList<>();
    mlarray.add((MLArray) buses);
    mlarray.add((MLArray) generators);
    mlarray.add((MLArray) loads);
    MatFileWriter writer = new MatFileWriter();
    writer.write(matFile.toFile(), mlarray);
}
 

开发者ID:itesla,
项目名称:ipst,
代码行数:18,
代码来源:MCSMatFileWriter.java

示例2: writeHistoricalData

点赞 3

import com.jmatio.io.MatFileWriter; //导入依赖的package包/类
public void writeHistoricalData(ForecastErrorsHistoricalData forecastErrorsHistoricalData) throws IOException {
        Objects.requireNonNull(forecastErrorsHistoricalData, "forecast errors historical data is null");
//        LOGGER.debug("Preparing stochastic variables mat data");
//        MLStructure stochasticVariables = stochasticVariablesAsMLStructure(forecastErrorsHistoricalData.getStochasticVariables());
        LOGGER.debug("Preparing injections mat data");
        MLCell injections = histoDataHeadersAsMLChar(forecastErrorsHistoricalData.getForecastsData().columnKeyList());
        LOGGER.debug("Preparing injections countries mat data");
        MLCell injectionsCountries =  injectionCountriesAsMLChar(forecastErrorsHistoricalData.getStochasticVariables());
        LOGGER.debug("Preparing forecasts mat data");
        MLDouble forecastsData = histoDataAsMLDouble("forec_filt", forecastErrorsHistoricalData.getForecastsData());
        LOGGER.debug("Preparing snapshots mat data");
        MLDouble snapshotsData = histoDataAsMLDouble("snap_filt", forecastErrorsHistoricalData.getSnapshotsData());
        LOGGER.debug("Saving mat data into " + matFile.toString());
        List<MLArray> mlarray = new ArrayList<>();
//        mlarray.add((MLArray) stochasticVariables );
        mlarray.add((MLArray) injections);
        mlarray.add((MLArray) forecastsData);
        mlarray.add((MLArray) snapshotsData);
        mlarray.add((MLArray) injectionsCountries);
        MatFileWriter writer = new MatFileWriter();
        writer.write(matFile.toFile(), mlarray);
    }
 

开发者ID:itesla,
项目名称:ipst,
代码行数:23,
代码来源:FEAMatFileWriter.java

示例3: writeToMatlab

点赞 3

import com.jmatio.io.MatFileWriter; //导入依赖的package包/类
/**
 * Write a CSV wordIndex to a {@link MLCell} writen to a .mat data file
 * 
 * @param path
 * @throws IOException
 */
public static void writeToMatlab(String path) throws IOException {
	final Path wordMatPath = new Path(path + "/words/wordIndex.mat");
	final FileSystem fs = HadoopToolsUtil.getFileSystem(wordMatPath);
	final LinkedHashMap<String, IndependentPair<Long, Long>> wordIndex = readWordCountLines(path);
	final MLCell wordCell = new MLCell("words", new int[] { wordIndex.size(), 2 });

	System.out.println("... reading words");
	for (final Entry<String, IndependentPair<Long, Long>> ent : wordIndex.entrySet()) {
		final String word = ent.getKey();
		final int wordCellIndex = (int) (long) ent.getValue().secondObject();
		final long count = ent.getValue().firstObject();
		wordCell.set(new MLChar(null, word), wordCellIndex, 0);
		wordCell.set(new MLDouble(null, new double[][] { new double[] { count } }), wordCellIndex, 1);
	}
	final ArrayList<MLArray> list = new ArrayList<MLArray>();
	list.add(wordCell);
	new MatFileWriter(Channels.newChannel(fs.create(wordMatPath)), list);
}
 

开发者ID:openimaj,
项目名称:openimaj,
代码行数:25,
代码来源:WordIndex.java

示例4: writeToMatlab

点赞 3

import com.jmatio.io.MatFileWriter; //导入依赖的package包/类
/**
 * Write a CSV timeIndex to a {@link MLCell} writen to a .mat data file
 * @param path
 * @throws IOException
 */
public static void writeToMatlab(String path) throws IOException {
	Path timeMatPath = new Path(path + "/times/timeIndex.mat");
	FileSystem fs = HadoopToolsUtil.getFileSystem(timeMatPath);
	LinkedHashMap<Long, IndependentPair<Long, Long>> timeIndex = readTimeCountLines(path);
	MLCell timeCell = new MLCell("times",new int[]{timeIndex.size(),2});
	
	System.out.println("... reading times");
	for (Entry<Long, IndependentPair<Long, Long>> ent : timeIndex.entrySet()) {
		long time = (long)ent.getKey();
		int timeCellIndex = (int)(long)ent.getValue().secondObject();
		long count = ent.getValue().firstObject();
		timeCell.set(new MLDouble(null, new double[][]{new double[]{time}}), timeCellIndex,0);
		timeCell.set(new MLDouble(null, new double[][]{new double[]{count}}), timeCellIndex,1);
	}
	ArrayList<MLArray> list = new ArrayList<MLArray>();
	list.add(timeCell);
	new MatFileWriter(Channels.newChannel(fs.create(timeMatPath)),list );
}
 

开发者ID:openimaj,
项目名称:openimaj,
代码行数:24,
代码来源:TimeIndex.java

示例5: saveFoldParameterLearner

点赞 3

import com.jmatio.io.MatFileWriter; //导入依赖的package包/类
private void saveFoldParameterLearner(int fold, int j, BilinearSparseOnlineLearner learner) {
	// save the state
	final File learnerOut = new File(String.format("%s/fold_%d", currentOutputRoot(), fold), String.format(
			"learner_%d", j));
	final File learnerOutMat = new File(String.format("%s/fold_%d", currentOutputRoot(), fold), String.format(
			"learner_%d.mat", j));
	learnerOut.getParentFile().mkdirs();
	try {
		IOUtils.writeBinary(learnerOut, learner);
		final Collection<MLArray> data = new ArrayList<MLArray>();
		data.add(CFMatrixUtils.toMLArray("u", learner.getU()));
		data.add(CFMatrixUtils.toMLArray("w", learner.getW()));
		if (learner.getBias() != null) {
			data.add(CFMatrixUtils.toMLArray("b", learner.getBias()));
		}
		final MatFileWriter writer = new MatFileWriter(learnerOutMat, data);
	} catch (final IOException e) {
		throw new RuntimeException(e);
	}
}
 

开发者ID:openimaj,
项目名称:openimaj,
代码行数:21,
代码来源:LambdaSearchAustrian.java

示例6: testMLCharUnicode

点赞 3

import com.jmatio.io.MatFileWriter; //导入依赖的package包/类
@Test
public void testMLCharUnicode() throws Exception
{
    //array name
    String name = "chararr";
    //file name in which array will be storred
    String fileName = "mlcharUTF.mat";
    File outFile = temp.newFile( fileName );
    //temp
    String valueS;

    //create MLChar array of a name "chararr" containig one
    //string value "dummy"
    MLChar mlChar = new MLChar(name, new String[] { "\u017C\u00F3\u0142w", "\u017C\u00F3\u0142i"} );
    MatFileWriter writer = new MatFileWriter();
    writer.write(outFile, Arrays.asList( (MLArray) mlChar ) );
    
    MatFileReader reader = new MatFileReader( outFile );
    MLChar mlChar2 = (MLChar) reader.getMLArray(name);

    assertEquals("\u017C\u00F3\u0142w", mlChar.getString(0) );
    assertEquals("\u017C\u00F3\u0142w", mlChar2.getString(0) );
    assertEquals("\u017C\u00F3\u0142i", mlChar2.getString(1) );        
}
 

开发者ID:gradusnikov,
项目名称:jmatio,
代码行数:25,
代码来源:MatIOTest.java

示例7: exportFlowToMatlab

点赞 2

import com.jmatio.io.MatFileWriter; //导入依赖的package包/类
public void exportFlowToMatlab(final int tmin, final int tmax) {
    if (!exportedFlowToMatlab) {
        int firstTs = dirPacket.getFirstTimestamp();
        if (firstTs > tmin && firstTs < tmax) {
            if (vxOut == null) {
                vxOut = new double[sizey][sizex];
                vyOut = new double[sizey][sizex];
            }
            for (Object o : dirPacket) {
                ApsDvsMotionOrientationEvent ev = (ApsDvsMotionOrientationEvent) o;
                if (ev.hasDirection) {
                    vxOut[ev.y][ev.x] = ev.velocity.x;
                    vyOut[ev.y][ev.x] = ev.velocity.y;
                }
            }
        }
        if (firstTs > tmax && vxOut != null) {
            ArrayList list = new ArrayList();
            list.add(new MLDouble("vx", vxOut));
            list.add(new MLDouble("vy", vyOut));
            try {
                MatFileWriter matFileWriter = new MatFileWriter(loggingFolder + "/flowExport.mat", list);
            } catch (IOException ex) {
                log.log(Level.SEVERE, null, ex);
            }
            log.log(Level.INFO, "Exported motion flow to {0}/flowExport.mat", loggingFolder);
            exportedFlowToMatlab = true;
            vxOut = null;
            vyOut = null;
        }
    }
}
 

开发者ID:SensorsINI,
项目名称:jaer,
代码行数:33,
代码来源:AbstractMotionFlowIMU.java

示例8: writeWP41ContinuousInputMatFile

点赞 2

import com.jmatio.io.MatFileWriter; //导入依赖的package包/类
public static void writeWP41ContinuousInputMatFile(Path outputfile, double[][] idata, int nsamples, double ir, double k) throws IOException {

        MLDouble dNsample = new MLDouble("N_Sample", new double[]{nsamples}, 1);
        MLDouble dIR = new MLDouble("IR", new double[]{ir}, 1);
        MLDouble dK = new MLDouble("K", new double[]{k}, 1);
        MLDouble data = Utils.matToMLDouble(idata, "X");

        List<MLArray> mlarray = new ArrayList<>();
        mlarray.add((MLArray) dNsample);
        mlarray.add((MLArray) dIR);
        mlarray.add((MLArray) dK);
        mlarray.add((MLArray) data);
        MatFileWriter writer = new MatFileWriter();
        writer.write(outputfile.toFile(), mlarray);
    }
 

开发者ID:itesla,
项目名称:ipst,
代码行数:16,
代码来源:Utils.java

示例9: writeWP41BinaryIndependentSamplingInputFile

点赞 2

import com.jmatio.io.MatFileWriter; //导入依赖的package包/类
public static void writeWP41BinaryIndependentSamplingInputFile(Path outputfile, double[] marginalExpectations) throws IOException {
    MLDouble data = Utils.vectToMLDoubleRow(marginalExpectations, "p");
    List<MLArray> mlarray = new ArrayList<>();
    mlarray.add((MLArray) data);
    MatFileWriter writer = new MatFileWriter();
    writer.write(outputfile.toFile(), mlarray);
}
 

开发者ID:itesla,
项目名称:ipst,
代码行数:8,
代码来源:Utils.java

示例10: writeWp41ContModule1Mat

点赞 2

import com.jmatio.io.MatFileWriter; //导入依赖的package包/类
public static void writeWp41ContModule1Mat(Path outputfile, double[][] matrix) throws IOException {
    LOGGER.debug("writeWp41ContModule1Mat - writing wp41 input X matrix data to file {}", outputfile);
    MLDouble data = Utils.matToMLDouble(matrix, "X");
    List<MLArray> mlarray = new ArrayList<>();
    mlarray.add((MLArray) data);
    MatFileWriter writer = new MatFileWriter();
    writer.write(outputfile.toFile(), mlarray);
    LOGGER.debug("writeWp41ContModule1Mat - X matrix data, written.");
}
 

开发者ID:itesla,
项目名称:ipst,
代码行数:10,
代码来源:Utils.java

示例11: writeMLArrayToPath

点赞 2

import com.jmatio.io.MatFileWriter; //导入依赖的package包/类
private void writeMLArrayToPath(Path fPath, List<MLArray> mlarray) throws IOException {
    try (OutputStream w = Files.newOutputStream(fPath)) {
        //using Writable channel to make it work both for 'standard' and shrinkwrap based filesystems
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        WritableByteChannel wbc = Channels.newChannel(baos);
        new MatFileWriter(wbc, mlarray);
        w.write(baos.toByteArray());
    }
}
 

开发者ID:itesla,
项目名称:ipst,
代码行数:10,
代码来源:DymolaAdaptersMatParamsWriter.java

示例12: testBenchmarkUInt8

点赞 2

import com.jmatio.io.MatFileWriter; //导入依赖的package包/类
@Test 
public void testBenchmarkUInt8() throws Exception
{
    final String fileName = "bigbyte.mat";
    final String name = "bigbyte";
    File outFile = temp.newFile( fileName );
    final int SIZE = 1024;    
    
    
    MLUInt8 mluint8 = new MLUInt8( name, new int[] { SIZE, SIZE } );
    
    //write array to file
    ArrayList<MLArray> list = new ArrayList<MLArray>();
    list.add( mluint8 );
    
    //write arrays to file
    new MatFileWriter( outFile, list );
    
    //read array form file
    MatFileReader mfr = new MatFileReader( outFile );
    MLArray mlArrayRetrived = mfr.getMLArray( name );
    
    final long start = System.nanoTime();
    for ( int i = 0; i < mlArrayRetrived.getSize(); i++ )
    {
        ((MLNumericArray<?>)mlArrayRetrived).get(i);
    }
    final long stop = System.nanoTime();
    System.out.println("--> " + (stop - start)/1e6 +  "[ns]");
           
    //test if MLArray objects are equal
    assertEquals("Test if value red from file equals value stored", mluint8, mlArrayRetrived);
}
 

开发者ID:gradusnikov,
项目名称:jmatio,
代码行数:34,
代码来源:MatIOTest.java

示例13: testFilteredReading

点赞 2

import com.jmatio.io.MatFileWriter; //导入依赖的package包/类
/**
 * Tests filtered reading
 * 
 * @throws IOException
 */
@Test 
public void testFilteredReading() throws IOException
{
    //1. First create arrays
    //array name
    String name = "doublearr";
    String name2 = "dummy";
    //file name in which array will be storred
    String fileName = "filter.mat";
    File outFile = temp.newFile( fileName );
    
    double[] src = new double[] { 1.3, 2.0, 3.0, 4.0, 5.0, 6.0 };
    MLDouble mlDouble = new MLDouble( name, src, 3 );
    MLChar mlChar = new MLChar( name2, "I am dummy" );
    
    //2. write arrays to file
    ArrayList<MLArray> list = new ArrayList<MLArray>();
    list.add( mlDouble );
    list.add( mlChar );
    new MatFileWriter( outFile, list );
    
    //3. create new filter instance
    MatFileFilter filter = new MatFileFilter();
    filter.addArrayName( name );
    
    //4. read array form file
    MatFileReader mfr = new MatFileReader( outFile, filter );
    
    //check size of
    Map<String, MLArray> content = mfr.getContent();
    assertEquals("Test if only one array was red", 1, content.size() );
    
}
 

开发者ID:gradusnikov,
项目名称:jmatio,
代码行数:39,
代码来源:MatIOTest.java

示例14: testMLStructure

点赞 2

import com.jmatio.io.MatFileWriter; //导入依赖的package包/类
/**
 * Test <code>MatFileFilter</code> options
 * @throws IOException 
 */
@Test
public void testMLStructure() throws IOException
{
    //array name
    //file name in which array will be storred
    String fileName = "mlstruct.mat";
    File outFile = temp.newFile( fileName );

    //test column-packed vector
    double[] src = new double[] { 1.3, 2.0, 3.0, 4.0, 5.0, 6.0 };
    
    //create 3x2 double matrix
    //[ 1.0 4.0 ;
    //  2.0 5.0 ;
    //  3.0 6.0 ]
    MLDouble mlDouble = new MLDouble( null, src, 3 );
    MLChar mlChar = new MLChar( null, "I am dummy" );
    
    
    MLStructure mlStruct = new MLStructure("str", new int[] {1,1} );
    mlStruct.setField("f1", mlDouble);
    mlStruct.setField("f2", mlChar);
    
    //write array to file
    ArrayList<MLArray> list = new ArrayList<MLArray>();
    list.add( mlStruct );
    
    //write arrays to file
    new MatFileWriter( outFile, list );
    
    //read array form file
    MatFileReader mfr = new MatFileReader( outFile );
    MLStructure mlArrayRetrived = (MLStructure)mfr.getMLArray( "str" );
    
    assertEquals(mlDouble, mlArrayRetrived.getField("f1") );
    assertEquals(mlChar, mlArrayRetrived.getField("f2") );
    

}
 

开发者ID:gradusnikov,
项目名称:jmatio,
代码行数:44,
代码来源:MatIOTest.java

示例15: testWritingManyArraysInFile

点赞 2

import com.jmatio.io.MatFileWriter; //导入依赖的package包/类
/**
 * Regression bug: Test writing several arrays into a single file.
 * 
 * @throws IOException
 */
@Test 
public void testWritingManyArraysInFile() throws IOException
{
    final String fileName = "multi.mat";
    File outFile = temp.newFile( fileName ); 
    
    //test column-packed vector
    double[] src = new double[] { 1.3, 2.0, 3.0, 4.0, 5.0, 6.0 };
    double[] src2 = new double[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 };
    double[] src3 = new double[] { 3.1415 };

    //create 3x2 double matrix
    //[ 1.0 4.0 ;
    //  2.0 5.0 ;
    //  3.0 6.0 ]
    MLDouble m1 = new MLDouble( "m1", src, 3 );
    MLDouble m2= new MLDouble( "m2", src2, 3 );
    MLDouble m3 = new MLDouble( "m3", src3, 1 );
    //write array to file
    ArrayList<MLArray> list = new ArrayList<MLArray>();
    list.add( m1);
    list.add( m2);
    list.add( m3);
    
    //write arrays to file
    new MatFileWriter( outFile, list );
    
    //read array form file
    MatFileReader mfr = new MatFileReader( outFile );
    
    //test if MLArray objects are equal
    assertEquals("Test if value red from file equals value stored", m1, mfr.getMLArray( "m1" ));
    assertEquals("Test if value red from file equals value stored", m2, mfr.getMLArray( "m2" ));
    assertEquals("Test if value red from file equals value stored", m3, mfr.getMLArray( "m3" ));
}
 

开发者ID:gradusnikov,
项目名称:jmatio,
代码行数:41,
代码来源:MatIOTest.java

示例16: testSingle

点赞 2

import com.jmatio.io.MatFileWriter; //导入依赖的package包/类
/**
 * Tests the mxSINGLE
 * @throws Exception
 */
@Test
public void testSingle() throws Exception
{
    
    Float[] expected = new Float[] { 1.1f, 2.2f, 3.3f };
    String  name = "arr";
    File outFile = temp.newFile( "singletmp.mat" );
    
    
    //create MLSingle type
    MLSingle single = new MLSingle( name, expected, 1);
    assertEquals(expected[0], single.get(0) );
    assertEquals(expected[1], single.get(1) );
    assertEquals(expected[2], single.get(2) );
    
    //Test writing the MLSingle
    MatFileWriter writer = new MatFileWriter();
    writer.write( outFile, Arrays.asList( (MLArray)single) );
    
    //Test reading the MLSingle
    MatFileReader reader = new MatFileReader();
    MLSingle readSingle = (MLSingle) reader.read( outFile ).get( "arr" );
    
    assertEquals( single, readSingle );
    
    //Test reading the MLSingle generated natively by Matlab
    MLSingle readSingleMatlabGenerated = (MLSingle) reader.read( new File("src/test/resources/single.mat") ).get( "arr" );
    
    assertEquals( single, readSingleMatlabGenerated );
    
}
 

开发者ID:gradusnikov,
项目名称:jmatio,
代码行数:36,
代码来源:MatIOTest.java

示例17: toFile

点赞 2

import com.jmatio.io.MatFileWriter; //导入依赖的package包/类
public static void toFile(File file, Matrix matrix, Object... parameters) throws IOException {
	MatFileWriter writer = new MatFileWriter();
	Collection<MLArray> matrixList = new ArrayList<MLArray>();
	matrixList.add(new MLDenseDoubleMatrix(matrix).getWrappedObject());
	writer.write(file, matrixList);
}
 

开发者ID:ujmp,
项目名称:universal-java-matrix-package,
代码行数:7,
代码来源:ExportMatrixMAT.java

示例18: createWriteToMatlab

点赞 2

import com.jmatio.io.MatFileWriter; //导入依赖的package包/类
private void createWriteToMatlab(LongWritable timeslot, Iterable<BytesWritable> manylines) throws IOException {
	System.out.println("Creating matlab file for timeslot: " + timeslot);
	MLSparse matarr = new MLSparse(String.format("values_%d", timeslot.get()), new int[] { wordIndex.size(), 2 }, 0, wordIndex.size() * 2);
	long Ttf = 0;
	long tf = 0;
	boolean set = false;
	for (BytesWritable word : manylines) {
		ByteArrayInputStream bais = new ByteArrayInputStream(word.getBytes());
		DataInputStream dis = new DataInputStream(bais);
		WordDFIDF idf = new WordDFIDF();
		idf.readBinary(dis);
		int wordI = dis.readInt();
		// writer.writeln(new String[]{wordI + "",timeI + "",idf.wf +
		// "",idf.tf + "",idf.Twf + "", idf.Ttf + ""});
		// writer.flush();
		// swriter.flush();
		if (!set) {
			tf = idf.tf;
			Ttf = idf.Ttf;
			set = true;
		}
		else {
			if (tf != idf.tf)
				throw new IOException("Error writing matlab file, tf doesn't match");
			if (Ttf != idf.Ttf)
				throw new IOException("Error writing matlab file, Ttf doesn't match");
		}
		matarr.set((double) idf.wf, wordI, 0);
		matarr.set((double) idf.Twf, wordI, 1);
	}
	MLInt64 tfMat = new MLInt64(String.format("tf_%d", timeslot.get()), new long[][] { new long[] { tf } });
	MLInt64 TtfMat = new MLInt64(String.format("Ttf_%d", timeslot.get()), new long[][] { new long[] { Ttf } });
	ArrayList<MLArray> list = new ArrayList<MLArray>();
	list.add(tfMat);
	list.add(TtfMat);
	list.add(matarr);
	Path outLoc = new Path(String.format(valuesLocation, timeslot.get()));
	FileSystem fs = HadoopToolsUtil.getFileSystem(outLoc);
	FSDataOutputStream os = fs.create(outLoc);
	new MatFileWriter(Channels.newChannel(os), list);
}
 

开发者ID:openimaj,
项目名称:openimaj,
代码行数:42,
代码来源:ReduceValuesByTime.java

示例19: testMLCell

点赞 2

import com.jmatio.io.MatFileWriter; //导入依赖的package包/类
/**
 * Test <code>MatFileFilter</code> options
 * @throws IOException 
 */
@Test 
public void testMLCell() throws IOException
{
    //array name
    String name = "doublearr";
    String name2 = "name";
    //file name in which array will be storred
    String fileName = "mlcell.mat";
    File outFile = temp.newFile( fileName );

    //test column-packed vector
    double[] src = new double[] { 1.3, 2.0, 3.0, 4.0, 5.0, 6.0 };

    //create 3x2 double matrix
    //[ 1.0 4.0 ;
    //  2.0 5.0 ;
    //  3.0 6.0 ]
    MLDouble mlDouble = new MLDouble( name, src, 3 );
    MLChar mlChar = new MLChar( name2, "none" );
    
    
    MLCell mlCell = new MLCell("cl", new int[] {2,1} );
    mlCell.set(mlChar, 0);
    mlCell.set(mlDouble, 1);
    
    //write array to file
    ArrayList<MLArray> list = new ArrayList<MLArray>();
    list.add( mlCell );
    
    //write arrays to file
    new MatFileWriter( outFile, list );
    
    //read array form file
    MatFileReader mfr = new MatFileReader( outFile );
    MLCell mlArrayRetrived = (MLCell)mfr.getMLArray( "cl" );
    
    assertEquals(mlDouble, mlArrayRetrived.get(1) );
    assertEquals(mlChar, mlArrayRetrived.get(0) );
    

}
 

开发者ID:gradusnikov,
项目名称:jmatio,
代码行数:46,
代码来源:MatIOTest.java

示例20: testMLCharArray

点赞 2

import com.jmatio.io.MatFileWriter; //导入依赖的package包/类
/**
 * Tests <code>MLChar</code> reading and writing.
 * 
 * @throws IOException
 */
@Test 
public void testMLCharArray() throws IOException
{
    //array name
    String name = "chararr";
    //file name in which array will be storred
    String fileName = "mlchar.mat";
    File   outFile = temp.newFile( fileName );
    //temp
    String valueS;

    //create MLChar array of a name "chararr" containig one
    //string value "dummy"
    MLChar mlChar = new MLChar(name, "dummy");
    
    //get array name
    valueS = mlChar.getName();
    assertEquals("MLChar name getter", name, valueS);
    
    //get value of the first element
    valueS = mlChar.getString(0);
    assertEquals("MLChar value getter", "dummy", valueS);
    
    //write array to file
    ArrayList<MLArray> list = new ArrayList<MLArray>();
    list.add( mlChar );
    
    //write arrays to file
    new MatFileWriter( outFile, list );
    
    //read array form file
    MatFileReader mfr = new MatFileReader( outFile );
    MLArray mlCharRetrived = mfr.getMLArray( name );
    
    assertEquals("Test if value red from file equals value stored", mlChar, mlCharRetrived);
    
    //try to read non existent array
    mlCharRetrived = mfr.getMLArray( "nonexistent" );
    assertEquals("Test if non existent value is null", null, mlCharRetrived);
}
 

开发者ID:gradusnikov,
项目名称:jmatio,
代码行数:46,
代码来源:MatIOTest.java

示例21: testMLDoubleArray

点赞 2

import com.jmatio.io.MatFileWriter; //导入依赖的package包/类
/**
 * Tests <code>MLDouble</code> reading and writing.
 * 
 * @throws IOException
 */
@Test 
public void testMLDoubleArray() throws IOException
{
    //array name
    String name = "doublearr";
    //file name in which array will be storred
    String fileName = "mldouble.mat";
    File outFile = temp.newFile( fileName );
    
    //test column-packed vector
    double[] src = new double[] { 1.3, 2.0, 3.0, 4.0, 5.0, 6.0 };
    //test 2D array coresponding to test vector
    double[][] src2D = new double[][] { { 1.3, 4.0 },
                                        { 2.0, 5.0 },
                                        { 3.0, 6.0 }
                                    };

    //create 3x2 double matrix
    //[ 1.0 4.0 ;
    //  2.0 5.0 ;
    //  3.0 6.0 ]
    MLDouble mlDouble = new MLDouble( name, src, 3 );
    
    //write array to file
    ArrayList<MLArray> list = new ArrayList<MLArray>();
    list.add( mlDouble );
    
    //write arrays to file
    new MatFileWriter( outFile, list );
    
    //read array form file
    MatFileReader mfr = new MatFileReader( outFile );
    MLArray mlArrayRetrived = mfr.getMLArray( name );
    
    //System.out.println( mlDouble.contentToString() );
    //System.out.println( mlArrayRetrived.contentToString() );
    //test if MLArray objects are equal
    assertEquals("Test if value red from file equals value stored", mlDouble, mlArrayRetrived);
    
    //test if 2D array match
    for ( int i = 0; i < src2D.length; i++ )
    {
        boolean result = Arrays.equals( src2D[i], ((MLDouble)mlArrayRetrived ).getArray()[i] );
        assertEquals( "2D array match", true, result );
    }
    
    //test new constructor
    MLArray mlDouble2D = new MLDouble(name, src2D );
    //compare it with original
    assertEquals( "Test if double[][] constructor produces the same matrix as normal one", mlDouble2D, mlDouble );
}
 

开发者ID:gradusnikov,
项目名称:jmatio,
代码行数:57,
代码来源:MatIOTest.java

示例22: testMLUInt8Array

点赞 2

import com.jmatio.io.MatFileWriter; //导入依赖的package包/类
/**
 * Tests <code>MLUint8</code> reading and writing.
 * 
 * @throws IOException
 */
@Test 
public void testMLUInt8Array() throws IOException
{
    //array name
    String name = "arr";
    //file name in which array will be storred
    String fileName = "mluint8tst.mat";
    File outFile = temp.newFile( fileName );
    
    //test column-packed vector
    byte[] src = new byte[] { 1, 2, 3, 4, 5, 6 };
    //test 2D array coresponding to test vector
    byte[][] src2D = new byte[][] { { 1, 4 },
                                    { 2, 5 },
                                    { 3, 6 }
                                    };

    //create 3x2 double matrix
    //[ 1.0 4.0 ;
    //  2.0 5.0 ;
    //  3.0 6.0 ]
    MLUInt8 mluint8 = new MLUInt8( name, src, 3 );
    
    //write array to file
    ArrayList<MLArray> list = new ArrayList<MLArray>();
    list.add( mluint8 );
    
    //write arrays to file
    new MatFileWriter( outFile, list );
    
    //read array form file
    MatFileReader mfr = new MatFileReader( outFile );
    MLArray mlArrayRetrived = mfr.getMLArray( name );
    
    //test if MLArray objects are equal
    assertEquals("Test if value red from file equals value stored", mluint8, mlArrayRetrived);
    
    //test if 2D array match
    for ( int i = 0; i < src2D.length; i++ )
    {
        boolean result = Arrays.equals( src2D[i], ((MLUInt8)mlArrayRetrived ).getArray()[i] );
        assertEquals( "2D array match", true, result );
    }
    
    //test new constructor
    MLArray mlMLUInt82D = new MLUInt8(name, src2D );
    //compare it with original
    assertEquals( "Test if double[][] constructor produces the same matrix as normal one", mlMLUInt82D, mluint8 );
}
 

开发者ID:gradusnikov,
项目名称:jmatio,
代码行数:55,
代码来源:MatIOTest.java

示例23: testMLSparse

点赞 2

import com.jmatio.io.MatFileWriter; //导入依赖的package包/类
/**
 * Tests <code>MLSparse</code> reading and writing.
 * 
 * @throws IOException
 */
@Test public void testMLSparse() throws IOException
{
    //array name
    String name = "sparsearr";
    //file name in which array will be storred
    String fileName = "mlsparse.mat";
    File outFile = temp.newFile( fileName );
    
    
    //test 2D array coresponding to test vector
    double[][] referenceReal = new double[][] { { 1.3, 4.0 },
            { 2.0, 0.0 },
            { 0.0, 0.0 }
        };
    double[][] referenceImaginary = new double[][] { { 0.0, 0.0 },
            { 2.0, 0.0 },
            { 0.0, 6.0 }
        };

    MLSparse mlSparse = new MLSparse(name, new int[] {3, 2}, MLArray.mtFLAG_COMPLEX, 5);
    mlSparse.setReal(1.3, 0, 0);
    mlSparse.setReal(4.0, 0, 1);
    mlSparse.setReal(2.0, 1, 0);
    mlSparse.setImaginary(2.0, 1, 0);
    mlSparse.setImaginary(6.0, 2, 1);
    
    //write array to file
    ArrayList<MLArray> list = new ArrayList<MLArray>();
    list.add( mlSparse );
    
    //write arrays to file
    new MatFileWriter( outFile, list );
    
    //read array form file
    MatFileReader mfr = new MatFileReader( outFile );
    MLArray mlArrayRetrived = mfr.getMLArray( name );
    
    //test if MLArray objects are equal
    assertEquals("Test if value red from file equals value stored", mlSparse, mlArrayRetrived);
    
    //test if 2D array match
    for ( int i = 0; i < referenceReal.length; i++ )
    {
        for (int j = 0; j < referenceReal[i].length; j++) {
            assertEquals( "2D array mismatch (real)", referenceReal[i][j], (double) ((MLSparse)mlArrayRetrived).getReal(i,j), 0.001);
        }
    }
    for ( int i = 0; i < referenceImaginary.length; i++ )
    {
        for (int j = 0; j < referenceImaginary[i].length; j++) {
            assertEquals( "2D array mismatch (imaginary)", referenceImaginary[i][j], (double) ((MLSparse)mlArrayRetrived).getImaginary(i,j), 0.001);
        }
    }
}
 

开发者ID:gradusnikov,
项目名称:jmatio,
代码行数:60,
代码来源:MatIOTest.java

示例24: testWritingMethods

点赞 2

import com.jmatio.io.MatFileWriter; //导入依赖的package包/类
@Test
public void testWritingMethods() throws IOException
{
    final String fileName = "nwrite.mat";
    final File f = temp.newFile(fileName);
    
    //test column-packed vector
    double[] src = new double[] { 1.3, 2.0, 3.0, 4.0, 5.0, 6.0 };

    //create 3x2 double matrix
    //[ 1.0 4.0 ;
    //  2.0 5.0 ;
    //  3.0 6.0 ]
    MLDouble m1 = new MLDouble( "m1", src, 3 );
    //write array to file
    ArrayList<MLArray> list = new ArrayList<MLArray>();
    list.add( m1);
    
    MatFileWriter writer = new MatFileWriter();
    
    writer.write(f, list);

    
    assertTrue("Test if file was created", f.exists() );
    
    MLArray array = null;
    
    //try to read it
    MatFileReader reader = new MatFileReader();
    reader.read(f, MatFileReader.MEMORY_MAPPED_FILE );
    array = reader.getMLArray("m1");
    assertEquals("Test if is correct file", array, m1);
    
    //try to delete the file
    assertTrue("Test if file can be deleted", f.delete() );
    
    writer.write(f, list);
    
    assertTrue("Test if file was created", f.exists() );
    reader.read(f, MatFileReader.MEMORY_MAPPED_FILE );
    assertEquals("Test if is correct file", reader.getMLArray("m1"), m1);

    
    //try the same with direct buffer allocation
    reader.read(f, MatFileReader.DIRECT_BYTE_BUFFER );
    array = reader.getMLArray("m1");
    assertEquals("Test if is correct file", array, m1);
    
    //try to delete the file
    assertTrue("Test if file can be deleted", f.delete() );
    
    writer.write(f, list);
    
    assertTrue("Test if file was created", f.exists() );
    reader.read(f, MatFileReader.DIRECT_BYTE_BUFFER );
    assertEquals("Test if is correct file", reader.getMLArray("m1"), m1);
    
    //try the same with direct buffer allocation
    reader.read(f, MatFileReader.HEAP_BYTE_BUFFER);
    array = reader.getMLArray("m1");
    assertEquals("Test if is correct file", array, m1);
    
    //try to delete the file
    assertTrue("Test if file can be deleted", f.delete() );
    
    writer.write(f, list);
    
    assertTrue("Test if file was created", f.exists() );
    reader.read(f, MatFileReader.HEAP_BYTE_BUFFER );
    assertEquals("Test if is correct file", reader.getMLArray("m1"), m1);
    
}
 

开发者ID:gradusnikov,
项目名称:jmatio,
代码行数:73,
代码来源:MatIOTest.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)