1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
/*
* Copyright (C) 2010 - DIGITEO - Sylvestre Ledru
*
* This file is released under the 3-clause BSD license. See COPYING-BSD.
*
*/
import org.scilab.modules.javasci.Scilab;
import org.scilab.modules.types.ScilabType;
import org.scilab.modules.types.ScilabDouble;
class Example1 {
public static void main(String[] args) {
try {
Scilab sci = new Scilab();
if (sci.open()) {
/* Send a Scilab instruction */
sci.exec("foo = [ 2, 4, 6; 4, 0, 10; 6, 10, 12 ];");
/* Retrieve the variable foo */
ScilabType foo = sci.get("foo");
/* Display the variable */
System.out.println("Representation of : " + foo);
/* Get the data and retrieve the 2,2 value */
double[][] aReal = ((ScilabDouble)foo).getRealPart();
System.out.println("foo[1,1] = " + aReal[1][1]);
/* Change the value of 2,2 */
aReal[1][1] = Math.PI;
/* Create a new variable */
ScilabDouble bar = new ScilabDouble(aReal);
/* Send it to Scilab */
sci.put("bar", bar);
/* Display it through Scilab */
sci.exec("disp(bar)");
sci.close();
} else {
System.out.println("Could not start Scilab ");
}
/* Can be improved by other exceptions: AlreadyRunningException,
* InitializationException, UndefinedVariableException,
* UnknownTypeException, etc
*/
} catch (org.scilab.modules.javasci.JavasciException e) {
System.err.println("An exception occurred: " + e.getLocalizedMessage());
}
}
}
|