logo for matrixlab-examples.com
leftimage for matrixlab-examples.com


Scilab Commands and Data Types


When you start Scilab in Windows, a new command window appears where you can see the typical menu bar. To get help about a specific command you can type

help function 

and a window will pop-up with an explanation and a short example of that function. 

Data Types

The fundamental data type is the double precision floating number. There are also different precision integers, Booleans, strings and other more specialized types. Roughly speaking, they are types of matrices, and a scalar variable is a special case of a matrix. Some of the data types are:

real or complex matrix, Boolean matrix, sparse matrix, matrix of integers (1, 2 or 4 bytes), matrix of graphic handles, array of strings, functions, lists and pointers.

Built-in function type(x) returns an integer which is the type of x. 

Function isreal(A) lets you know whether the variable A is real or complex. Boolean variables are represented as %T and %F, true and false respectively. ~A gives the element-wise negation of the elements of the boolean matrix A. For example, 

-->x = %T
 x  = 

  T 

-->~x
 ans  = 

  F  
 

In a given condition, any number other than 0 is true. Function bool2s(x) changes boolean matrix to a zero-one matrix. For example, 

-->bool2s([t %t %f %t])
 ans  = 

    1.    1.    0.    1. 

-->bool2s([2.3 0 10 -1])
 ans  = 

    1.    0.    1.    1.
 

Strings can be declared with single or double quotes: 

-->s = 'this is a string with single quotes'
 s  = 

 this is a string with single quotes 

-->s = "this is a string with single quotes"
 s  = 

 this is a string with single quotes 

 

Scilab can also handle structures, that means groups of different types of data under one name. Data is accessed using fields. Using dot notation you can start adding fields to a variable. In the following example, the variable V is a structure with two fields, 'name' and 'age'.
 

-->V.name = 'Charlie Brown'
 V  = 

   name: "Charlie Brown" 

-->V.age = 7
 V  = 

   name: "Charlie Brown"
   age: 7 

-->typeof(V)
 ans  = 

 st  

The same result can be achieved with command struct(field1, value1, field2, value2...). For example,
 

v = struct('name', 'Snoopy', 'age', 4)
 v  = 

   name: "Snoopy"
   age: 4
 

Cells are arrays where you can store different types of data (in each cell). Method entries allows to fill in the cells.  Curly brackets are used instead of parentheses.

-->c = cell(3, 3)
 c  =
 

!{}  {}  {}  !
!            !
!{}  {}  {}  !
!            !
!{}  {}  {}  !
 

-->c(1, 1).entries = 'good morning'
 c  = 

!"good morning"  {}  {}  !
!                        !
!{}              {}  {}  !
!                        !
!{}              {}  {}  !
 

-->c(3, 3).entries = 'good evening'
 c  =
 

!"good morning"  {}  {}              !
!                                    !
!{}              {}  {}              !
!                                    !
!{}              {}  "good evening"  !

 

-->c(2, 2).entries = 2
 c  =
 

!"good morning"  {}  {}              !
!                                    !
!{}              2   {}              !
!                                    !
!{}              {}  "good evening"  !

 

Lists in Scilab / Scicoslab 

Aside from cells and structures, Scilab can work with lists.
This is a first approach with lists... 

list(A1,....An) creates a list with elements Ai which are arbitrary Scilab objects (matrix, list, ...). 

list() creates the empty list (0 elements). 
 

Operations on lists  

[x, y, z, ...] = L(v) where v is a vector of indices. This is an extraction.
[x, y, z] = L(:) extracts all the elements. 

L(i) = a insertion at index i.  

L($ + 1) = e appends an element in queue. 

L(0) = e appends an element in head. 

L(i) = null() removes the ith element of the list L. 

L3 = lstcat(L1, L2) concatenation of two lists.

nb_elm = size(L) or nb_elm = length(L) number of elements of a list; you can use either form. 


 From 'Scilab Commands ' to Matlab home

 From 'Scilab Commands' to Scilab
 

Top


footer for matlab page