First Steps¶

Table of contents¶

  1. The console
  2. The editor
  3. The variable browser and the command history
  4. Docking
  5. Using exec
  6. Help
  7. Demonstration
  8. ATOMS, the packaging system of Scilab

In this section, we make our first steps with Scilab and present some simple tasks we can perform with the interpreter.
There are several ways of using Scilab. Here, we present the method using the console in the interactive mode.

We also present the management of the graphical windows with the docking system. Finally, we present three features of Scilab:

  • the embedded help,
  • the demonstrations,
  • ans the ATOMS system, a packaging system for external modules.

The console ¶

The first way is to use Scilab interactively, by typing commands in the console, analyzing the results and continuing this process until the final result is computed. This document is designed so that the Scilab examples which are executed here or copied into your console.

After double-clicking the icon to launch Scilab, Scilab environment by default consists of the following docked windows:

  • console,
  • files browser,
  • variables browser,
  • command history,
  • news feed.

scilab-2024.0.0.png

In the console after the prompt -->, just type a command and press the < Enter > key (Windows and Linux) or < Return > key (Mac OS X) on the keyboard to obtain the corresponding result.

In the following example, the function disp is used in the interactive mode to print out the string "Hello World!".

In [1]:
s = "Hello World!"
disp(s)
 s  = 
  "Hello World!"

  "Hello World!"

When we edit a command, we can use the keyboard, as with a regular editor. We can use the left $\leftarrow$ and right $\rightarrow$ arrows in order to move the cursor on the line and use the < Backspace > and < Suppr > keys in order to fix errors in the text.

In order to get access to previously executed commands, we use the up arrow $\uparrow$ key. This lets us browse the previous commands by using the up $\uparrow$ and down $\downarrow$ arrow keys.

The < Tab > key provides a very convenient completion feature. In the following session, we type the statement disp in the console. Then we can type on the < Tab > key, which makes a list appear in the console.

completion.png

Scilab displays a listbox, where items correspond to all functions which begin with the letters "disp". We can then use the up and down arrow keys to select the function we want.

The auto-completion works with functions, variables, files and graphic handles and makes the development of scripts easier and faster.

Other example:

In [2]:
57 / 4
2 + 9
 ans  =
   14.25
 ans  =
   11.

Mention: Before the result ans is displayed for "answer".

The editor ¶

Typing directly into the console has two disadvantages:

  • it is not possible to save the commands
  • and it is not easy to edit multiple lines of instruction.

So, Scilab provides an editor for editing scripts easily.

scinotes.png

The editor is accessed

  • from the menu of the console, under the Applications > SciNotes menu,
  • from the console by scinotes function,
  • or the first icon in the toolbar console accessories-text-editor.png

The editor opens with a default file named "Untitled 1".

This editor manages several files at the same time where we edit five files at the same time.

There are many features which are worth mentioning in this editor. The most commonly used features are under the Execute menu.

  • Execute ...file with no echo (Ctrl+Shift+E under Windows and Linux, Cmd+Shift+E under Mac OS X): the file is executed without writing the program in the console (saving the file first is mandatory).
  • Execute ... file with echo (Ctrl+L under Windows and Linux, Cmd+L under Mac OS X): rewrites the file into the console and executes it.
  • Execute ... the selection with echo (Ctrl+E under Windows and Linux, Cmd+E under Mac OS X): rewrites the selection chosen with the mouse into the console and executes it or executes the file data until the caret position defined by the user.

We can also select a few lines in the script, right click (or Cmd+Click under Mac), and get the context menu which is presented in following figure.

scinotes_right_click.png

The Edit menu provides a very interesting feature, commonly known as a "pretty printer" in most languages. This is the Edit > Correct Indentation feature, which automatically indents the current selection. This feature is extremely convenient, because it formats algorithms, so that the if, for and other structured blocks are easy to analyze.

The editor provides a fast access to the inline help. Indeed, assume that we have selected the disp statement. When we right-click in the editor, we get the context menu, where the Help about "disp" entry opens the help page associated with the disp function.

scinotes_help_display.png

The variable browser and the command history ¶

Scilab provides a variable browser, which displays the list of variables currently used in the environment.

var_browser.png

We can access this browser through the menu Applications > Variable Browser, but the function browsevar has the same effect.

We can double click on a variable, which opens the variable editor. We can then interactively change the value of a variable by changing its content in a cell. On the other hand, if we change the variable content within the console, we must refresh the content of the dialog box by pushing the refresh button in the toolbar of the Variable Editor.

var_editor.png

The Command History dialog allows browsing through the commands that we have previously executed. This dialog is available in the menu Applications > Command History.

commandhistory.png

We can select any command in the list and double-click on it to execute it in the console. The right-click opens a context menu which lets us evaluate the command or edit it in the editor.

Docking ¶

The graphics in Scilab version 5 has been updated so that many components are now based on Java. This has a number of advantages, including the possibility to manage docking windows.

As in the default Scilab environment, where the console, files and variables browsers and command history are all together docked windows in Scilab can be repositioned in a single one. For example, the user can choose to position the editor in the default environment of Scilab.

To dock a window in another one, first identify the blue horizontal bar under Windows, or black under Mac OS X and Linux, at the top of the window in the toolbar containing a question mark on the right.

  • Under Windows and Linux, click on this bar with the left mouse button and, while maintaining the click, move the mouse pointer in the desired window.
  • Under MacOS X, click on this bar and while maintaining the click, move it the desired window.

A rectangle appears indicating the future positioning of the window. When the position is the one you want, release the mouse button. To cancel and bring out the window, click on the small arrow on the right of the same bar.

docking.png

Using exec ¶

When several commands are to be executed, it may be more convenient to write these statements into a file with Scilab editor. To execute the commands located in such a file, the exec function can be used, followed by the name of the script. This file generally has the extension .sce or .sci, depending on its content:

  • files having the .sci extension contain Scilab functions and executing them loads the functions into Scilab environment (but does not execute them),
  • files having the .sce extension contain both Scilab functions and executable statements.

Executing a .sce file has generally an effect such as computing several variables and displaying the results in the console, creating 2D plots, reading or writing into a file, etc...

Assume that the content of the file myscript.sce is the following.

disp("Hello World !")

In the Scilab console, we can use the exec function to execute the content of this script.

-->exec("myscript.sce")
-->disp("Hello World !")
 Hello World !   

In practical situations, such as debugging a complicated algorithm, the interactive mode is used most of the time with a sequence of calls to the exec and disp functions.

Help ¶

To access the online help,

  • click on ? > Scilab Help in the menu bar
  • use help function
  • click on help-browser.png

help_scilab.png

Examples of use can be executed in Scilab and edited in SciNotes in using the associated buttons in the example framework.

To get help with any function, type help in the console followed by the name of the appropriate function. For example

--> help cos

displays help for cos function.

Demonstrations ¶

Scilab provides a collection of demonstration scripts, which are available

  • from the console, in the menu ? > Scilab Demonstrations
  • from the icon toolbar x-office-presentation.png

scilab_demo.png

ATOMS, the packaging system of Scilab ¶

In this section, we present ATOMS, which is a set of tools designed to install pre-built toolboxes.

Scilab is designed to be extended by users, who can create new functions and use them as if they were distributed with Scilab. These extensions are called "toolboxes" or "external modules". The creation of a new module, with its associated help pages and unit tests, is relatively simple and this is a part of the success of Scilab.

However, most modules cannot be used directly in source form: the module has to be compiled so that the binary files can be loaded into Scilab. This compilation step is not straightforward and may be even impossible for users who want to use a module based on C or Fortran source code and who do not have a compiler. This is one of the issues that ATOMS has solved: modules are provided in binary form, allowing the user to install a module without any compilation phase and without Scilab compatibilities issues.

An extra feature for the user is that most modules are available on all platforms.

ATOMS is the packaging system of Scilab external modules. With this tool, prebuilt (i.e. pre-compiled) Scilab modules, can be downloaded, installed and loaded. The dependencies are managed, so that if a module A depends on a module B, the installation of the module A automatically installs the module B. This is similar to the packaging system available in most GNU/Linux/BSD distributions. ATOMS modules are available on all operating systems on which Scilab is available, that is, on Microsoft Windows, GNU/Linux and Mac OS X. For example, when a ATOMS module is installed on Scilab running on a MS Windows operating system, the pre-built module corresponding to the MS Windows version of the module is automatically installed. The web portal for ATOMS is https://atoms.scilab.org.

This portal presents the complete list of ATOMS modules and let the developers of the modules upload their new modules.

There are two ways to install an ATOMS module. The first way is to use the atomsGui function, which opens a Graphical User Interface (GUI) which lets the user browse through all the available ATOMS modules. This tool is also available from the menu "Applications > Module manager - ATOMS" of the Scilab console. Within the GUI, we can read the description of the module and simply click on the "Install" button or from the icon of toolbar package-x-generic.png

scilab_atoms.png

The second way is to use the atomsInstall function, which takes the name of a module as input argument.
For example, to install the scicv module, the following statement should be executed:

--> atomsInstall("scicv")

Then Scilab should be restarted and the scicv module (and, if any, its dependencies) are automatically loaded.

More details on ATOMS are available at Wiki-Modules.