You are on page 1of 112

Scilab *

http://www.scilab.org.cn/
2007.7.1


0. []
1. Scilab
1.1. Scilab
1.2. Scilab
1.3. Scilab
1.4. Scilab
2. Scilab
2.1.
2.2. Scilab
2.3. Scilab
2.4.
2.5.
3. Scilab
3.1. SCI
3.2.
3.3.
3.4.
3.5.
4. Scilab
4.1.
4.2.
4.3.
5. Scilab
5.1.
5.2.
5.3.
5.4.
5.5.
6. Scilab
6.1.
6.2.
6.3.
6.4.
6.5.
7. Scilab

Scilab *

7.1.
7.2.
7.3.
7.4.
8. Scilab
8.1.
8.2.
9. Scilab
10. Scicos
10.1. Scicos
10.2. Scicos
10.3. Scicos
10.4. Scicos
11. Scilab
11.2
12. Scilab
12.1. C
12.2. Java
13. MatlabScilab
14. Scilab
15. Scilab
16 Scilab
Scilab

Scilab 0

2007.7.1

Scilab 0.04

Scilab4.1 Scilab
Scilab Scilab Scilab Scilab
Scilab Scilab Scicos Scilab

,, Scilab
, Scilab
.

,,,
,,
2 .

email

Java

sinclairzhou@gmail.com

Java

figo2008lgq@163.com

Scicos

kcgrid2004@163.com

bat01@mails.tsinghua.edu.cn

sharrie2006@gmail.com

daifz@matsue-ct.jp
(
SIP
Toolbox)

ycwang_nwu@msn.com

04

pengzhe1113@gmail.com

zd4004@163.com

shiqi.yu@gmail.com

.
. 2 .
1

Scilab 0

sinclairzhou@gmail.com,sharrie2006@gmail.com,figo2008lgq@163.com,kcgrid2004@163.com,
bat01@mails.tsinghua.edu.cn,daifz@matsue-ct.jp,ycwang_nwu@msn.com,pengzhe1113@gmail.c
om,zd4004@163.com,shiqi.yu@gmail.com

kengawk@163.com,hnnier@sina.com,olympic_games2008@hotmail.com

Scilab 0

1. SCILAB
SCILAB INRIAENPC
SCILAB Scientific
LaboratorySCILAB

10,000

2. SCILAB

INRIA 1994
SCILAB SCILAB
SCILAB ----SCILAB
INRIA Francois Delebecque, Claude Gomez, Maurice Goursat, Ramine Nikoukhah
Serge Steer ENPC Jean-Phillippe Chancelier.
SCILAB
SCILAB
MATLAB

SCILAB
SCILAB
SCILAB

SCILAB
INRIA 2002
SCILAB Consortium SCILAB
SCILAB
SCILAB
3. SCILAB
INRIA

SCILAB
SCILAB SCILAB
SCILAB

Scilab 0

INRIA ENPC SCILAB

SCILAB 863
SCILAB

SCILAB CIRAD
Philippe de Reffye INRIA
LIAMA SCILAB
SCILAB

SCILAB 20012002 SCILAB


LIAMA 2002 SCILAB
2003 SCILAB
2003 - SCILAB
2003,2003 SCILAB SCILAB
SCILAB
SCILAB SCILAB

Scilab *

2007.7.1
+************

1. Scilab
1.1. Scilab
Scilab(Scientific Laboratory) INRIA

SCILAB SCILAB
SCILAB
SCILAB SCILAB

SCILAB
1
2
3
Intersci
FORTRAN C SCILAB SCILAB


SCILAB 3 SCILAB
FORTRAN C SCILAB Windows Linux
UNIX SCILAB MATLAB
Cleve Moler 1980 MATLAB

1.2. Scilab

1.2.1.Windows

Scilab *

Scilab

Scilab

()

Scilab *

1.2.2.Linux

MAKE

1.3. Scilab

File
-> New Scilab Scilab
-> Exec Sclab
->Open Sclab
->Load Scilab
->Save Scilab
->Chang Directoy Scilab
->Get Current Directoy Scilab
->Print Setup
->Print
->Exit
Edit
->Select all
->Copy
->Paste
->Empty Clipboard

Scilab *

Preferences
->Language
->Colors
->Toolbar
->File's Association
->Choose Font
->Clear History Scilab

->Clear Command Window


->Console Scilab
Control
->Resume

->Abort
->Interrupt
->
->
->
Editor
Scilab
Applications
->Scicos Scilab
->Edit Graph
->M2SCI Matlab Scilab
->Browser Variables
?
->Scilab HELP
->Configure
->Scilab Demos Scilab
->
->
->
->
->
->
->
->
->

Scilab *

.sav Scilab

1.4. Scilab

Scilab

Scilab *

2007.7.1
+

2. Scilab
Scilab
Scilab Scilab

2.1. Scilab
Scilab Scilab
Scilab

2.2.
2.2.1.
Scilab Scilab
Scilab
ans : ans

2.2.2.
Scilab

a=1
b=a+1
Scilab ";"

Scialb "//"
Clear

Scilab *

2.2.3.
Scilab
%i

%pi=3.1415927

%ee=2.7182818

%eps(%eps1+%eps=1 )
%inf
%nan``NotANumber'' respectively.
%ss s=poly(0,'s')
%t 1==1

%f~%t

2.2.4.
Scilab Browser Variables

Scilab Save

Save
Load

Load

Browser Variables browsevar(); Scilab

Scilab *

2.3. Scilab
2.3.1.

Scilab *

-->a=5+2*%i
a =

5. + 2.i

-->B=-2+%i;

-->b=4-3*%i
b =

4. - 3.i

-->a*b
ans =

26. - 7.i

-->a*B
ans =

- 12. + i

Scilab
-->B
B

- 2. + i

Scilab *

-->b
b

4. - 3.i

Scilab ;
-->a=5+2*%i
a

5. + 2.i

-->a=5+2*%i;

-->

2.3.2.

-->v=[2,-3+%i,7]
v =

2. - 3. + i

7.

-->v'
ans =

Scilab *

2.
- 3. - i
7.

-->w=[-3;-3-%i;2]
w =

- 3.
- 3. - i
2.

-->v'+w
ans =

- 1.
- 6. - 2.i
9.

-->v*w
ans =

18.

-->w'.*v
ans =

- 6.

8. - 6.i

14.

Scilab *

-->v=[2,-3+%i,7]
v

2.

- 3. + i

7.

-->v=[2;-3+%i;7]
v

2.
- 3. + i
7.

[]
-->Empty=[]
Empty

[]

'
-->A=[1,2,3]
A =

1.

2.

3.

-->A'
ans =

1.

Scilab *

2.
3.

-->A=[1+%i,2+2*%i]
A =

1. + i

2. + 2.i

-->A=[1+%i,2+2*%i,3+%i]
A =

1. + i

2. + 2.i

3. + i

-->A'
ans =

1. - i
2. - 2.i
3. - i

(.*)(./)


-->v=[1 +3]
v =

1.

3.

Scilab *

-->w=[1 + 3]
w =

4.

-->w=[1+ 3]
w =

4.

-->u=[1, + 8- 7]
u =

1.

1.

-->v=5:-.5:3
v =

5.

4.5

4.

3.5

3.

1
-->v=1:10
v

1.

2.

3.

4.

5.

6.

7.

8.

oneszeros
9

9.

10.

Scilab *

-->v=[1 5 6]
v =

1.

5.

6.

-->ones(v)
ans =

1.

1.

1.

-->ones(v')
ans =

1.
1.
1.

-->ones(1:4)
ans =

1.

1.

1.

1.

-->3*ones(1:4)
ans =

3.

3.

3.

3.

-->zeros(v)
ans =

10

Scilab *

0.

0.

0.

-->zeros(1:5)
ans =

0.

0.

0.

0.

0.

oneszeros
1 0

:
=

-->s = 1:4
s =
1.

2.

3.

4.

-->s = 1:0.4:4
s =

column 1 to 6
1.

1.4

1.8

2.2

2.6

3.

column 7 to 8
3.4

3.8

Linspace
-->s = linspace(1,100,10)
s =

column 1 to 6

11

Scilab *

1.

12.
column

67.

78.

23.

34.

45.

56.

7 to 10
89.

100.

Logspace
-->s = logspace(1,100,10)
s =
1.0D+50 *

column 1 to 3
1.000D-49

1.000D-38

1.000D-27

column 4 to 6
1.000D-16

0.00001

1000000.

column 7 to 9
1.000D+17

1.000D+28

1.000D+39

2.3.3.

.*./

-->A=[2 1 4;5 -8 2]
A =

2.

1.

4.

12

Scilab *

5. - 8.

2.

-->b=ones(2,3)
b =

1.

1.

1.

1.

1.

1.

1.

4.

5. - 8.

2.

-->A.*b
ans =

2.

-->A*b'
ans =

7.

7.

- 1. - 1.

ones(a,b) a b 1
zeros(a,b)ab 1

-->A=[1 2;3 4]
A =

1.

2.
13

Scilab *

3.

4.

-->B=[5 6;7 8];

-->C=[9 10;11 12];

-->D=[A,B,C]
D =

1.

2.

5.

6.

9.

10.

3.

4.

7.

8.

11.

12.

-->E=matrix(D,3,4)
E =

1.

4.

6.

11.

3.

5.

8.

10.

2.

7.

9.

12.

-->F=eye(E)
F =

1.

0.

0.

0.

0.

1.

0.

0.

0.

0.

1.

0.

-->G=eye(4,3)
G =

1.

0.

0.
14

Scilab *

0.

1.

0.

0.

0.

1.

0.

0.

0.

DmatrixE
DD
ED

eye(a,b)ab 1(E
abE)

help sparse

2.3.4.
%t%f

==~==~
Bor(B)and(B)

-->%t
%t =

-->[1,2]==[1,3]
ans =

15

Scilab *

T F

-->[1,2]==1
ans =

T F

-->a=1:5; a(a>2)
ans =

3.

4.

5.

-->A=[%t,%f,%t,%f,%f,%f];

-->B=[%t,%f,%t,%f,%t,%t]
B =

T F T F T T

-->A|B
ans =

T F T F T T

-->A&B
ans =

T F T F F F

16

Scilab *

2.3.5.
Scilab

[ ]

, concatenation

( )

extraction m=a(k)

( )

insertion: a(k)=m

'

.*

.\

./

.^

17

Scilab *

2.4. Scilab
2.4.1.
,
C= A+B
C=A-B

2.4.2.
C = A* B
C=A.*B

2.4.3.
C= A\B
C=A/B

2.4.4.
C = inv (A)

2.4.5.
C = A^p
C=A.^p

18

Scilab *

2.4.6.
C = A'

(List)

2.5.
Scilab
-->s ="aaa"+"bbb"
s =
aaabbb

2.5.1.
i = strindex(str1,str2)
-->i=strindex("abcdef","bc")
i =
2.

2.5.2.

-->s = convstr("abc",'u')
s =
ABC

-->s = convstr("ABC",'l')
s =
19

Scilab *

abc

2.5.3.
-->strsubst('abcdef','bc','00')
ans =
a00def

20

Scilab 3

2007.7.1
+************

3. Scilab
3.1. Scilab
Scilab Scilab scipad

SCI 2 SCI SCE


SCI exec
GETF

clear
a=1
b=2
c=a+b
c.sci
exec('C:\Documents and Settings\Administrator\\c.sci');disp('exec done');
--> a =
1.
b =
2.
c =
3.

3.2.
Scilab

3.2.1.

Scilab 3

3.2.1.1.
z

if

if
if []

end

clear
a=2;
if(a==2)
a=a+1
end

--> a =
3.

if-else
if []
1
else
2
end

clear
a=1;
if(a==2)
a=a+1
else
a=a-1
end

a =
0.

elseif

Scilab 3

if [ 1]
1
elseif [ 2]
2
end
:
clear
a=3;
if(a==2)
a=a+1
elseif a==1
a=a-1
else
a=10
end

--> a =
10.

select

select 0
case 1 then
1
case 2 then
2
....
case n then
n
else
n+1
end

a=1;
b=1;
c=2;
select a

Scilab 3

case b then
c=a+b;
c=c+1;
case c then
c=c-1;
else
c=a;
end
disp(c);

-->
3.

3.2.2.
3.2.2.1.

for

for = ::

end
1 for end

clear
for a =3:2:9
c=a;
disp(c);
end

-->
3.
4

Scilab 3

5.
7.
9.

clear;
M = [1,2,3,4];
c=0;
for a=M
c=c+1;
disp(c);
end

-->
1.
2.
3.
4.

Scilab For

3.3.
Scilab SCI"getf"
Scilab
kc.sci
function c = abc(a,b)
// tese
c =a +b
5

Scilab 3

-->getf("c:\kc\kc.sci")
-->r = abc(3,5)
r =
8.
SCI

clear
function c = abc2(a,b)
// tese
c =a +b
endfunction
r = abc2(5,9);
disp(r)

-->
14.

3.4.

Scilab 3

Scilab 3

Scilab 4

+************
2007.7.1

4. Scilab
4.1.

4.2.

Scilab 4

Scilab 5

+************
2007.7.1

5. Scilab
5.1.

5.2.

5.3.

5.4.

5.5.

5.6.

Scilab 5

Scilab 5

Scilab 6

+************
2007.7.1

6. Scilab
6.1.

6.2.

6.3.

6.4.

6.5.

6.6.

6.7.

Scilab 6

6.8.

6.9.

6.10.

6.11.

6.12.

Scilab 6

Scilab 7

+************
2007.7.1

7. Scilab

Scilab 7

Scilab 8

+************
2007.7.1

8.

Scilab

Scilab 8

Scilab 9

+************
2007.7.1

9. Scilab
( Scilab 5.0

Java )

Scilab 9

Scilab 10

+
2007.7.1

10. Scicos
10.1. Scicos

10.2. Scicos

Scilab 10

Scilab 10

Scilab 10

Scilab 10

Scilab 10

Scilab 10

Scilab 10

10.3. Scicos

Scilab 10

10.4. Scicos

Scilab 10

10

Scilab 11

+************
2007.7.1

11. Scilab

Scilab 11

11.1.
11.1.1.

11.1.2.

11.1.3.

11.2.
11.2.1.

11.2.2.

11.2.3.

11.3.
11.3.1.

11.3.2.

11.3.3.

11.4.
11.4.1.

11.4.2.

11.4.3.

Scilab 11

11.5.
11.5.1.

11.5.2.

11.5.3.

11.6.
11.6.1.

11.6.2.

11.6.3.

11.7.
11.7.1.

11.7.2.

11.7.3.

11.8.
11.8.1.

11.8.2.

11.8.3.

Scilab 11

2007.7.1

11Scilab

11.2
scilab SIP (Scilab Image Processing)
Ricardo Fabbri <rfabbri@if.sc.usp.br> http://siptoolbox.sourceforge.net/
SIP
Jocelyn Druel <Jocelyn.druel1@LIBERTYSURF.FR>
SIP <A SIP User Manual>
11.2.1
SIP ImageMagick ImageMagick SIP
Scilab

SIP GPL license

SIPhttp://siptoolbox.sourceforge.net/
Windows Linux
install.txt
SIP SIP
SIP
0.3.0 102
SIP Scilab
SIP
exec(SIPDEMO)
SIP
11.2.2
1 imread 1
--mat = imread(ararauna.jpg);
ararauna.jpg mat
1

Scilab 11

--chdir(SIPDIR+images)

1 imread( )

imread
0 1

2 imshow 2
--xbasc( );

()

--imshow(mat);

2 imshow( )

3 imwrite
--imwrite(mat, /home/test.jpg); ( linux )
4 --- 3
--dmat = mat * 0.6
--xset(window, 2);

()
2

Scilab 11

--imshow(dmat);

5 --- 4
--image = imread(SIPDIR+images/ararauna.jpg);
--[r c] = size(image); ()
--image(10, : , 1) = 1; ( 10 )
--image( : , 10, 2) =1; ( 10 )

4
3

Scilab 11

--imshow(image);

6 im2gray 5

--mat = imread(ararauna.jpg);
--gmat = im2gray(mat);
--imshow(mat);
--xset(window, 1); xbasc( ); imshow(gmat);

gray_imread
gmat = gray_imread(ararauna.jpg);

7 im2bw 6
im2bw 2
--mat = imread(ararauna.jpg);
--bmat = im2bw(mat, 0.7);

( 0.7)

--imshow(bmat);
--bbmat = im2bw(mat, 0.5);

( 0.5)
4

Scilab 11

--xset(window, 1); xbasc( ); imshow(bbmat);

11.2.3
1
Scilab

11

--mat1 = imread(image1.jpg);
--mat2 = imread(image2.jpg);
--mat_mean = (mat1 + mat2) / 2;
--xbasc( ); imshow(mat_mean);

12

--mat = imread(image.jpg);
--pmat = mat .* mat; ()
--tmat = mat * mat;

()

Scilab 11

13

imread 0 1 8bit

--mat1 = imread(image1.jpg);
--mat2 = imread(image2.jpg);
--mat_modulo = uint8(mat1 * 255) uint8(mat2 * 255);
--mat_modulo = double(mat_modulo) / 255;

14

( 256)

Scilab 12

+************
2007.7.1

12. Scilab
12.1. C

Scilab 12

Scilab 12

+
2007.7.1

12.2. Java
Scilab Java Java Scilab
%sci-home%\bin javasci\*.class Java
sci-home Scilab
Scilab
SciComplex Scilab
SciComplexArray Scilab
SciDouble Scilab
SciDoubleArray Scilab
SciString Scilab
SciStringArray Scilab
Scilab Scilab
Scilab Java Java
Scilab Scilab
SciComplexSciComplexArraySciDoubleSciDoubleArray
SciStringSciStringArray
Scilab Scilab SciDoubleArray
javasci

Scilab 12

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

public static void main(String[] args) {


SciDoubleArray a = new SciDoubleArray("A",4,1, new double [] {1,2,3,4} );
SciDoubleArray b = new SciDoubleArray("B",4,1, new double [] {3,1,2,4} );
SciDoubleArray c = new SciDoubleArray("C",4,1, new double [] {0,0,0,0} );
Scilab.Exec("disp(A);");
Scilab.Exec("disp(B);");
Scilab.Exec("disp(C);");
a.disp();
b.disp();
c.disp();
Scilab.Exec("C=A+B;");
a.Get();
b.Get();
c.Get();
a.disp();
b.disp();
c.disp();
Scilab.Finish();
}

3~5 Java abc Scilab


ABCSciDoubleArray
Scilab Scilab.Exec Scilab
Scilab Scilab disp(A)
Scilab Scilab 24
Scilab.Finish() Java Scilab Scilab
Scilab Scilab
JobdispGetSend a.Job("A=rand(4,4)") a
Scilab disp Get
Scilab Send Java
Scilab 15 Scilab "C=A+B;"
18 c.Get(); C Get

Scilab Java Scilab Java


Scilab

Scilab 13

+************
2007.7.1

13. Matlab Scilab

Scilab 13

Scilab 14

+************
2007.7.1

14. Scilab

Scilab 14

Scilab 15

+
2007.7.1

15. Scilab

mytoolbox 8
* macros: Scilab ( Scilab .sci buldmacros
loadmacros
* src: .c .f buildsrc
* sci_gateway: buildsci_gateway
* help: eng fr.xml buildhelp
loadhelp
* etc: .html, .pdf, .txt, .jpeg, ...
* unit tests: .tst files
* demos:
* includes: .h
:
* readme.txt:
* builder.sce: builder
* loader.sce: loader
* license.txt:

2 builder loader
builder loader macros,src, help builder loader

Scilab 15

3
builder loader buildmacros.sce loadmacros.sce

macros Scilab .sci


mytoolbox .sci foo1
A XX A
foo1.sci
function [X]=foo1(A)
// A
// A
if type(A)<>1 then
error("type of input argument must be a double");
end
if size(A,1)<>size(A,2) then
error("input argument must be a square matrix");
end
//
X=[];
for i=1:size(A,1)
if A(i,i)>0 then
X($+1)=A(i,i);
end
end
endfunction

3.1 builder
builder macros .sci
mytoolboxlib=
toolbox_name +'lib' builder
buildmacros.sce get_absolute_file_path
genlib
buildmacros.sce

Scilab 15

mode(-1)
//
toolboxname='mytoolbox' //
pathB=get_absolute_file_path('buildmacros.sce') //
disp('Building macros in ' +pathB) //
genlib(toolboxname+'lib',pathB,%t) //
clear pathB genlib toolboxname //
'mytoolbox'

3.2 loader
loader macros lib scilab builder
loadmacros.sce lib Scilab
load
loadmacros.sce
mode(-1) //
pathL=get_absolute_file_path('loadmacros.sce') //
disp('Loading macros in ' +pathL) //
load(pathL+'/lib')
// lib scilab
clear pathL
//

4 src
primitive Scilab C Fortran
Scilabprimitive sci_gateway
C Scilab primitive
CheckRhs CheckLhs

Scilab rhs
SCI/examples

4.1
C

Scilab 15

a:
vectsum C sci_sumab
Scilab sumab
Scilab "sci_"
C vectsum sci_sumab Scilab -->
Y=sumab(A,B )
vectsum.c
void vectsum(int n, double * a, double * b, double * y)
{
int k;
for (k = 0; k < n; ++k)
y[k] = a[k] + b[k];
}
sci_sumab.c
#include "stack-c.h"
extern int vectsum(int n, double * a, double * b, double * y);
void sci_sumab(char *fname){
int l1, m1, n1, l2, m2, n2, l3, n;
/* 1 - Check the number of inputs/outputs arguments
int minlhs=1, maxlhs=1, minrhs=2, maxrhs=2;
CheckRhs(minrhs,maxrhs) ;
CheckLhs(minlhs,maxlhs) ;

*/

/* 2 - Check inputs arguments type, and get the size and the address
in the Scilab stack of the inputs arguments */
GetRhsVar(1, "d", &m1, &n1, &l1);
GetRhsVar(2, "d", &m2, &n2, &l2);
/* 3 - Check that the inputs arguments have the same size */
/* it's possible to use the chekdims and getscalar functions to make these checks*/
n=m2*n2;
if( n1!=n2 || m1!=m2)
{
cerro("inputs arguments must have the same size");
return 0;
}

Scilab 15

if(n1!=0 && m1!=0)


if(n1!=1 && m1!=1)
{
cerro("inputs arguments must be vectors");
return(0);
}

/* 4 - Create a new variable corresponding to the output argument */


CreateVar(3,"d",&m2,&n2,&l3);
/* 5 -call vectsum routine: returns in stk(l3) the sum of a and b*/
vectsum(n,stk(l1),stk(l2),stk(l3));
/* 6 - Specif ouput argument */
LhsVar(1) = 3;
return 0;
}
: call CheckRhsVar(minrhs,maxrhs) and CheckLhsVar(minlhs,maxlhs) instructions
CheckRhsVar function uses the arguments minrhs and maxrhs to check that: minrhs <= number of
input arguments <= maxrhs The number of inputs and outputs arguments (respectively 2 and 1) of
vectsum are constant, so minrhs=maxrhs=2 and minlhs=maxlhs=1, but for certains functions (see
example2) they can be variable, in this case the variables minrhs/minlhs and maxrhs/maxlhs are
different.
We can use directly the defined variables Rhs(=number of inputs) and Lhs(=number of outputs)
instead of the functions CheckRhsVar and CheckLhsVar.
: call GetRhsVar(1,"d",&m1,&n1,&l1) instruction
GetRhsVar function checks that the type of inputs arguments of sumab are correct, and gets their
size and their address in the Scilab stack.
We describe below all arguments of GetRhsVar function:
* 1 : corresponds to the position on the stack of the first input argument of sumab, i.e A, (2
corresponds to B,...)
* m1 : gets the rows number of A (m2 for B)
* n1 : gets the columns number of A (n2 for B)
* l1 : gets the address of A in the Scilab stack (l2 for B)
: call CreateVar(3,"d",&m2,&n2,&l3) instruction
CreateVar function creates in the Stack at the 3th position a variable which corresponds to the

Scilab 15

output argument of vectsum (here Y)


* 3 : position of the created variable in the stack. This position (here 3) must follows the
position of the last input argument (here2) of sumab
* "d": sets the type of the created variable, here double
* m2: sets the rows number of the created variable(here equal to the rows number of the
second input argument B: m2)
* n2: sets the columns number of the first created variable (here equal to the columns number
of the second input argument B: n2)
* l3: gets the address of the created variable in the Scilab stack
: call vectsum(n,stk(l1),stk(l2),stk(l3)) instruction
The C function vectsum returns in stk(l3) the sum of stk(l1) and stk(l2) (i.e a and b)
: call LhsVar(1) = 3 instruction
The first output argument (here Y) of sumab takes the value of the variable placed in the 3th
position on the stack (i.e stk(l3))
b:
In the second example we describe the interface program named sci_fun of the Scilab primitive
named fun.
This function call the C routines fun1 and fun2 and has 2 syntaxes which are:
First syntax:
--> [X, Y ]=fun(A);
Given a vector A, this function returns the positives components of A in a vector X and the sum of
its positives components in a scalar Y.
Second syntax:
--> [X ]=fun(A);
Given a vector A, this function returns the positives components of A in a vector X.
The number of outputs arguments (i.e Lhs value) is variable: for the first syntax Lhs=1, for the
second syntax Lhs=2. The number of intputs arguments (i.e Rhs value) is constant: Rhs=1 (first
and second syntax).
So the interface program must check that: 1<=Lhs<=2 (set minlhs=1, maxlhs=2) and Rhs=1 (set
minrhs=maxrhs=1)
fun1.c (the C function fun1 creates the vector X and the scalar Y. It calls the C function fun2 to get
the needed size of X in order to allocate the corresponding memory place)
extern void fun2(double *, int, int *);

Scilab 15

void fun1(double * a, int na, int * nx, double ** x , double * y){


int i, k1=0;
*y=0;
fun2(a, na, nx);
*x=(double *)malloc((*nx)*sizeof(double));
*y=0;
for(i=0;i<na;i++)
if(a[i]>0) {
*(*x+k1)=a[i];
*y += a[i];
k1++;
};
}
fun2.c
void
{

fun2(double * a, int na, int * nx)


int i;
*nx=0;
for(i=0;i<na;i++)
if (a[i]>0)
(*nx)++;

}
sci_fun.c
#include "stack-c.h"
extern void fun1(double * ,

int, int *, double **, double *);

int sci_fun(char *fname)


{
int la, ma, na, m=1, nx, i, lx, ls;
double * x, s;
/* 1 - Check the number of inputs and outputs arguments */
/* You can use the variables: Lhs and Rhs */
int minlhs=1, maxlhs=2, minrhs=1, maxrhs=1;
CheckRhs(minrhs,maxrhs) ;
CheckLhs(minlhs,maxlhs) ;
/* 2 - Check the rhs type, get the rows number (ma) and the columns number (na) of rhs,
and its address (la) in the Scilab stack (first position) */

Scilab 15

GetRhsVar(1, "d", &ma, &na, &la);


/* 3 - Check rhs is a vector */
if(ma!=0 && na!=0 )
{
if(ma!=1 && na!=1)
{
cerro("input argument must be a vector");
return(0);
}
}
fun1(stk(la), na*ma, &nx, &x, &s);
/* 4 - Create the place for the first output argument x ( a vector of doubles, size: 1*nx )
to the address lx in the Scilab stack (second position) */
CreateVar(2, "d", &m, &nx, &lx);
/* if there are two outputs variables then: Create the place for the second output
s ( a double, size 1*1) to the address ls in the Scilab stack (third position) */
/* get the value of s, and put it in the Scilab stack */
if(Lhs==2)
{
CreateVar(3, "d", &m, &m, &ls);
*stk(ls)=s;
}
/* get the components of x, and put them in the Scilab stack */
for(i=0;i<nx;i++)
stk(lx)[i]=x[i];
/* free memory */
free(x);
/* 5 - Specification of outputs variables */
LhsVar(1) = 2;
if(Lhs==2)
LhsVar(2) = 3;
return 0;
}

Scilab 15

4.2 builder
src sci_gateway primitives fun sumab builder (fun1.c,
fun2.c, sci_fun.c, vectsum.c, sci_sumab.c)
builder
* src builder buildersrc C
ilib_for_link

* interface builder buildsci_gateway


C Fortran loader ilib_build

loader addinter Scilab addinter


buildsrc.sce
ilib_for_link('mytoolboxsrc',['fun1.o' 'fun2.o','vectsum.o'],[],"c")
buildsci_gateway.sce
// must be run from this directory
ilib_name = 'libmytoolbox'
// interface library name
files = ['sci_fun.o', 'sci_sumab.o']; // objects files
libs = ["../src/libmytoolboxsrc"]
// other libs needed for linking
table = [ 'fun', 'sci_fun';
'sumab','sci_sumab'];
// table of (scilab_name,interface-name)
// do not modify below
ilib_build(ilib_name,table,files,libs)
The ilib_name value is the interface library name, the vector files contains all the object interface
files,
the vector libs contains the libraries needed for linking (here the library included in the src
directory),
the variable table contains the primitives names (first column) and the corresponding interfaces
programs names (second column)

5
.xml buildhelp loadhelp

Scilab 15

Unix/Linux sabcmd Sablotron



XML

http://www.scilab.org/download/index_download.php?page=related_tool.html
5.1 .xml
.xml .xml
Langagetitletypedate short description
help
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<!DOCTYPE MAN SYSTEM "/home/scilab/scilab-3.0/man/manrev.dtd">
<MAN>
<LANGUAGE>eng</LANGUAGE>
<TITLE>sumab</TITLE>
<TYPE>Scilab Function </TYPE>
<DATE>20-Mar-2006</DATE>
<SHORT_DESCRIPTION name="add
here</SHORT_DESCRIPTION>

function

name">

add

short

decription

<CALLING_SEQUENCE>
<CALLING_SEQUENCE_ITEM>add function syntax</CALLING_SEQUENCE_ITEM>
</CALLING_SEQUENCE>
<PARAM>
<PARAM_INDENT>
<PARAM_ITEM>
<PARAM_NAME>add param name</PARAM_NAME>
<PARAM_DESCRIPTION>
<SP>
: add here the parameter description
</SP>
</PARAM_DESCRIPTION>
<PARAM_ITEM>
<PARAM_NAME>add param name</PARAM_NAME>
<PARAM_DESCRIPTION>
<SP>
: add here the parameter description
</SP>
</PARAM_DESCRIPTION>

10

Scilab 15

</PARAM_ITEM>
</PARAM_INDENT>
</PARAM>
<DESCRIPTION>
<DESCRIPTION_INDENT>
<DESCRIPTION_ITEM>
<P>
Add here a paragraph of the function description.
Other paragraph can be added
</P>
</DESCRIPTION_ITEM>
<DESCRIPTION_ITEM>
<P>
Add here a paragraph of the function description
</P>
</DESCRIPTION_ITEM>
</DESCRIPTION_INDENT>
</DESCRIPTION>
<EXAMPLE><![CDATA[
Add here scilab instructions and comments
]]></EXAMPLE>
<SEE_ALSO>
<SEE_ALSO_ITEM> <LINK> add a key here</LINK> </SEE_ALSO_ITEM>
<SEE_ALSO_ITEM> <LINK> add a key here</LINK> </SEE_ALSO_ITEM>
</SEE_ALSO>
<BIBLIO>
<Add here the function bibliography if any
</BIBLIO>
<AUTHORS>
<AUTHORS_ITEM label='enter here the author name'>
Add here the author references
</AUTHORS_ITEM>
</AUTHORS>
<USED_FUNCTIONS>
Add here the used function name and references
</USED_FUNCTIONS>

11

Scilab 15

</MAN>

5.2 builder
builder buildhelp.sce whatis.htm
.xml .html xmltohtml
> function)
buildhelp.sce
mode(-1) // slient
path=get_absolute_file_path('builhelp.sce'); //
add_help_chapter("Title1",path);
//
xmltohtml(path,"Title1")
// xml html
clear path add_help_chapter get_absolute_file_path //

5.3 loader
loader loadhelp.sce Scilab
loadhelp.sce
mode(-1) // slient
path=get_absolute_file_path('loadhelp.sce');//
add_help_chapter("Title1",path);//
clear path add_help_chapter get_absolute_file_

5.4 builder loader


builder loader builder loader

builder.sce
mode(-1);
mainpathB=get_absolute_file_path('builder.sce');
chdir(mainpathB);
if isdir('src') then // src
chdir('src');
// src

12

Scilab 15

exec('buildsrc.sce'); // src builder.sce


chdir('..');
//
end
//end if;
if isdir('sci_gateway') then
chdir('sci_gateway');
exec('buildsci_gateway.sce');
chdir('..');
end
if isdir('macros') then
chdir('macros');
exec('buildmacros.sce');
chdir('..');
end
if isdir('help') then
chdir('help');
exec('buildhelp.sce');
chdir('..');
end
clear mainpathB
loader.sce
mode(-1);
mainpathL=get_absolute_file_path('loader.sce');
chdir(mainpathL);
if isdir('sci_gateway') then
chdir('sci_gateway');
exec('loader.sce');
chdir('..');
end
if isdir('macros') then
chdir('macros');
exec('loadmacros.sce');
chdir('..');
end
if isdir('help') then
chdir('help');
exec('loadhelp.sce');
chdir('..');
end
clear mainpathL

13

Scilab 15

5.5
* :
http://www.scilab.org/contrib/index_contrib.php?page=howto.html
* mytoolbox.zip.
*
http://www.scilab.fr/contrib/index_contrib.php?page=upload.html
http://sourceforge.net
SourceForge.net (SVN CVS)
Bug

14

Scilab 16

+************
2007.7.1

16. Scilab

16.1. Scilab
16.1.1.

16.1.2.

16.2. Scilab
16.2.1.

Scicos Hardware Description Language Tools (Scicos-HDL 0.4)


Scicos
Scicos-HDL Scilab/Scicos 3
(2004-2007) Linux Windows Scicos
4 50 VHDLverilog
Scicos-HDL0.4
VHDLverilog 2
HDL LGPL Scicos
Scicos http://scicoshdl.sourceforge.net

16.2.2.

Scilab 16

16.3. ==

Scilab 16

Scilab *

+************

Scilab
scilab
1.
help
apropos
ans
clear
exit SCILAB
quit SCILAB
save
exec
mode
getversion SCILAB
ieee
who
edit
type
what SCILAB
format
chdir
getenv
mkdir
pwd
evstr
2.

-
*
.*
^
.^

/
./.
==
~= <
1

Scilab *

>
=
&,and
|,or
~,not
:
( )
[ ]
{ }
.
,
;
//
=
'
'
.'
ans
%eps ,
%i = (-1)
%inf
%pi , =3.1415926535897....
3.
abort
break
case select
continue forwhile
else if
elseif if
end forwhileif
for
if
otherwise switch
pause
return
select
then if
while
eval
feval
function
global
isglobal

Scilab *

error
lasterror
sprintf
warning
4.
acos
acosh
acot
acoth
acsc
acsch
asin
asinh
atan
atanh
cos
cosh
cotg
coth
sin
sinh
tan
tanh
exp
log
log10
log2 2
sqrt
abs
conj
imag
real
ceil ()
fix
floor ()
round
sign
gsort
erf
erfc
gamma gamma
interp
interpln
intsplin

Scilab *

smooth
spline
quarewave
sign
double
5.
eye
zeros
ones 1
rand
genmarkov Markov
linspace
logspace
logm
cumprod
cumsum
toeplitz Toeplitz
disp
length
size
diag
find 1
matrix
rot90 90
sub2ind
tril
triu
conj
companion
det
norm
nnz
null
orth
rank
trace
cond
rcond
inv
lu LU
pinv
qr QR
givens Givens
linsolve

Scilab *

lyap Lyapunov
hess Hessenberg
poly
schur Schur
expm
expm1 Pade
expm2
expm3
funm
logm
sqrtm
6.
spec
gspec
bdiag ,
eigenmarkov Markov
pbig
svd
sva
7.
cumprod
cumsum
hist
max
mean
median
min
prod
sort
std
sum
trapz
corr
8.
sparse ()
adj2sp
full
mtlb_sparse SCILABMATLAB
sp2adj
speye
sprand

Scilab *

spzeros
lufact LU
lusolve
spchol Cholesky
9.
diary
disp
file
input
load
mclose
mget
mgetl ASCII
mgetstr
mopen
mput
mfscanf ASCII
print
read
save
strartup
write
xgetfile
x_dialog Xwindow
Tk_Getvar Tk
Tk_EvalFile Tk
10.
deff
edit
function
functions SCILAB
genlib

get_function_path
getd
getf
lib
macro SCILAB
macrovar
newfun
11.

Scilab *

code2str SCILAB
convstr
emptystr
grep
part
str2code SCILAB
string
strings SCILAB,
strcat
strindex
strsubst
12.
date
getdate
timer CPU
13.
plot2d
champ 2
champ1 2
contour2d
errbar
grayplot
xgrid
histplot
Matplot
14.
plot3d
plot3d1
param3d
param3d1
contour
hist3d
geom3d
15.
xpoly
xpolys
xrpoly
xsegs
xfpoly
xfpolys

Scilab *

xrect
xfrect
xrects
xarc
xarcs
xfarc
xfarcs
xarrows
16. ,
xstring
xstringb
xtitle
xaxis
plotframe
isoview ()
square ()
xsetech
xchange
subplot
17.
colormap
getcolor
addcolor
graycolormap
hotcolormap ()
xset
xget
getsymbol
18.
xsave
xload
xbasimp PS
xs2fig Xfig
xbasc
xclear
driver
xinit
xend
xbasr
replot
xdel

Scilab *

xname
19.
bode
gainplot ()
nyquist
m_circle M
chart
black Black
evans
sgrid s
plzr -
zgrid z
20.
graphics
xclick
locate
xgetmouse
21.
abcd
cont_mat
csim
dsimul
feedback
flts
frep2tf
freq
g_margin
imrep2ss
lin
lqe Kalman
lqg LQG
lqr LQ
ltitr
obscont
observer
obsv_mat
p_margin
phasemag
ppol
repfreq
ricc Riccati

Scilab *

rtitr
sm2ss
ss2ss
ss2tf
stabil
tf2ss
time_id SISO
22.
augment
bstap Hankel
ccontrg H
dhnorm H
h2norm H
h_cl
h_inf H
h_norm H
hankelsv Hankel
leqr HLQ
linf
riccati Riccati
sensi
23.
arma ARMA
arma2p AR
armac ARMAX
arsimul ARMAX
noisegen
odedi
prbs_a
reglin
24.
artest Arnold
bifish
boucle
chaintest
gpech
fusee
lotest Lorennz
mine
obscontl
portr3d

10

Scilab *

portrait
recur
systems
tangent
tadinit
25.
bvode
dasrt
dassl
datafit
derivative
fsolve
impl
int2d
int3d
intg
leastsq
linpro
lmisolver
ode
ode_discrete
ode_root
odedc /
optim
quapro
semidef
26.
coeff
coffg
degree
denom
derivat
determ
factors
hermit Hermit
horner
invr
lcm
ldiv
numer
pdiv
pol2des

11

Scilab *

pol2str
polfact
residu
roots
simp
systmat
27.
%asn
%k Jacobi
%sn Jacobi
analpf
buttmag Butterworth
cepstrum
cheb1mag Chebyshev
cheb2mag Chebyshev
chepol Chebyshev
convol
corr ,
cspect ()
dft
fft
filter
fsfirlin FIR
hank Hankel
hilb Hilbert
iir IIR
intdec
kalm Kalman
mese
mfft
mrfit
phc Markov
srkf Kalman
sskf Kalman
system
wfir FIR
weiener Weiener()
window
yulewalk
zpbutt Buthererworth
zpch1 Chebyshev
28.

12

Scilab *

analyze
auread *.au
auwrite *.au
lin2mu
loadwave *.wav
mapsound
mu2lin
playsnd
savewave *.wav
wavread *.wav
wavwrite *.wav
29.
ascii ASCII
excel2sci ASCIIExcel
fun2string SCILABASCII
mfile2sci MATLABMSCI
mtlb_load MATLAB4
matlb_save MATLAB4
pol2tex TeX
sci2for SCILABFORTRAN
texprint TeXSCILAB
translatepaths MATLAB SCI

13

Scilab *

14

Scilab *

15

You might also like