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


Scilab Tutorial - Hello, World!

Now that you have installed Scilab or Scicoslab (they started being the same software), you're prepared for the basics. Let's get right down to start learning how to program on these possible matrix-lab alternatives. 

 


Starting Scilab – Scicoslab

These are the regular icons for each software.

Scilab icon      Scicoslab icon
 

The Scilab Screen

 
After Scilab is loaded, your screen looks something like this:

Opening screen for Scilab

This "Welcome" message appears each time you start Scilab (the image actually corresponds to a Scicoslab session). The screen offers you two options:  

  • You can type “help” on the command window to see Scilab's built-in help system.
  • You can start to code there or use the editor.  

You can type “clc” to clear the command window. That’s clearing the screen to begin typing. 
 

You can open the Editor by using the top menu.

 Scilab - top menu

Let's begin with a look at the various elements of the Scilab screen that will help you create programs and process text. 
 

The Scipad Editor

You can open the editor using the top menu of the command window or by typing scipad() 

The cursor indicates where the next character you type will appear on the screen.

 scipad editor

 
In the lower bar of the editor window there are two numbers. They indicate the current location of the cursor. The first number tells you which row (line) the cursor is in; the second number tells you which column the cursor is in.  

Across the top of the screen or current window is the menu bar. The menu bar contains the names for all the Scilab drop-down menus.  

You can work in only one window at a time, although it's easy to switch between the two (just click on the one that you need). The window you're currently working in is called the active window.  Note that the title of the Editor window remains “Untitled” until you name the program you type and save it on disk. 
 

Your First Program with Scilab or Scicoslab

Now that you've had a little hands-on experience with Scilab, you're ready to type in your first program. Typing in a program is quite straightforward. All you need to do is type in the lines exactly as we show them here, and press Enter at the end of each line.  

Use the Editor, type the following two lines:   

clc
disp('Hello, World!')

Save the file as ‘hello_world’. The extension .sce will be added automatically. 

You should have something similar to this image:

Scilab - hello world!

 

Running or Executing your code  

To run your first script (or program, or code, whatever you want to call it) use the Execute menu, on the editor window.  

You’ll clear the output window (command window) with the first line, and then the words Hello, World! will be displayed, like this:

 
Scilab firs program

 

What you just typed in, although it's only two lines long, is a complete Scilab program.

 

You've learned about one Scilab keyword, disp (for display), which 1ets your program put information on the screen. Another Scilab keyword is clc (for CLear Command window) which allows your script to completely erase the output screen.  

You can also run your Scilab script by typing  

exec hello_world.sce  

on your command window. The final effect will be the same.

The line above assumes that you’re working in the same directory that you used when you saved your file. If you’re not working in the same directory, you have to change that, otherwise Scilab won’t run your code and will display an error.  

pwd is a command used to verify your working directory.
cd is a command used to change your current directory.

You can always look for the details of commands and functions by typing  

help built-in function

on your command window, and you’ll get an explanation from the Scilab’s online help.  

A variation on the line to execute your file could be something like this:  

exec('C:\scilab_files\hello_world.sce') 

where we’re assuming that you’re working in the directory called C:\scilab_files in a Windows environment.  

You can also type tk_getfile on the command window, which creates a dialog window for file selection. 


 From 'Scilab Tutorial' to Matlab home

 From 'Scilab Tutorial' to Scilab


Top


footer for matlab page