scilab magic with scilab-5.4.1+ (soon)


In [1]:
# you must have scilab in your path, like below 
import os
os.environ["PATH"]  = os.environ["PATH"]+";"+r"C:\Users\famille\AppData\Local\scilab-5.4.1\bin"

In [2]:
# this currently suppose to have done pip install import scilab2py 
# with scilab2py  > 0.3 (not yet out)
import scilab2py
import numpy as np
sci = scilab2py.Scilab2Py()
x = sci.eval("zeros(3,3)")
x


Out[2]:
array([[ 0.,  0.,  0.],
       [ 0.,  0.,  0.],
       [ 0.,  0.,  0.]])

In [3]:
%load_ext scilab2py.ipython

In [4]:
x = %scilab 2+2


4.0

In [5]:
x = %scilab [1 2; 3 4];
x


[[ 1.  2.]
 [ 3.  4.]]
Out[5]:
array([[ 1.,  2.],
       [ 3.,  4.]])

In [6]:
a = [1, 2, 3]

%scilab_push a
%scilab a = a * 2;
%scilab_pull a
a


Out[6]:
array([[ 2.,  4.,  6.]])

In [7]:
%%scilab -i x -o y
y = x + 3;
y


[[ 4.  5.]
 [ 6.  7.]]

In [8]:
%%scilab -f svg

xset("fpf"," ")
contour2d(1:10,1:10,rand(10,10),5,rect=[0,0,11,11]);


[[ 0.82763768  0.66215437  0.49667106  0.33118775  0.16570444]]
0102468135791101024681357911

In [9]:
%%scilab -f jpg

# simple plot using z = f(x, y)
t = [0: 0.3: 2 * %pi]';
z = sin(t) * cos(t');
plot3d(t, t, z);



In [12]:
sci=scilab2py.Scilab2Py()

In [13]:
sci.eval("2+2")


Out[13]:
4.0

In [11]:
%%scilab -f png

[x, y] = meshgrid(0:0.1:3);
r = sin(x - 0.5).^2 + cos(y - 0.5).^2;
surf(x, y, r);



In [12]:
%%scilab -g
plot([1,2,3])
# brings up a Scilab plotting GUI

In [13]:
%scilab exists ones


0.0
Out[13]:
0.0

In [ ]: