You are on page 1of 6

Foxes Team

Foxes Team Pagina 1 20/08/2007


Addin for exchanging matrices between Excel and Scilab
v.1.0, Aug. 2007
by Foxes Team

Introduction

Scilab is a very nice freeware program for quick
and interactive computations with vectors and
matrices, real and complex numbers. In
general, Scilab is a numerical matrix system..


Many times we need to compare matrix results in different environment.
This little addin allows the exchange of matrices between Scilab and Excel

How to install it
Unzip and place all the files in a folder of your choice. This addin are contained entirely in this
directory. Your system is not modified in any other way.
Now, follow the usual procedure for installing Excel Addins:
1) Open Excel
2) Select <Addins...> from the <Tools> menu
3) In the Addins Manager, search for and select Excel_Scilab_IO.xla
4) Click OK
If all goes right you should see a welcome pop-up and two new entries added at the <Edit> menu
Copy Matrix to SCILAB
Paste Matrix from SCILAB

How to use it

Use these commands is very easy.

Copy Matrix from Excel to Scilab

1. in Excel, select the matrix and run "Copy Matrix to Scilab "
2. in Scilab, give the command A = evstr(clipboard('paste'));
(*) alternatively, at the Scilab prompt, write A= and give Ctrl+V

Paste Matrix from Scilab to Excel

1. in Scilab, give the command clipboard('copy', A);
(*) alternatively, select the matrix and give Ctrl+C
2. in Excel, select the cell where you want to paste and run "Paste Matrix from Scilab"

(*) Only for small matrices


Let's see how it works by examples
Foxes Team
Foxes Team Pagina 2 20/08/2007
Example - How to export a matrix from Excel into Scilab
Select in the matrix that you want to export and then run the command " Copy Matrix to SCILAB" in
Excel Edit menu




Now let's go to Scilab and give the command A = evstr(clipboard('paste'));
Give Enter at the end. The variable A will contains the 5x5 matrix






An alternative faster procedure, suitable only for small matrices, consists to write at the Scilab
prompt the variable A followed by "=" and after give the paste command CTRL+V
The matrix definition appears on the line; gives Enter to assign the matrix to the variable A

Example - How to export a matrix from Scilab into Excel
Assume to compute the inverse of A and assign it to the variable B.
Than give the command clipboard('copy', A); in order to save the variable B into the
Window clipboard




In Excel, select the starting cell where you want to copy and run the command " Paste Matrix from
Scilab" in Excel Edit menu. That's all.
Foxes Team
Foxes Team Pagina 3 20/08/2007

An alternative method, usable when the matrix
is small (that is, when the matrix is not
wrapped)
consists on that: select the scilab matrix and
after that give the copy command CTRL+C
In Excel, paste the matrix with the command
Edit/Paste Matrix from Scilab, as above.

This procedure copies the matrix as it is shown.
If the matrix has decimal number, remember to
give the command format(20);B in order to
show all the decimals



A more bigger examples
The following 15x15 band-diagonal matrix can be easily exported





As we can see, in that case, the view-space is sufficient for visualizing the entire matrix in the
standard format (not wrapped)

Foxes Team
Foxes Team Pagina 4 20/08/2007
Assume to have the following 35x35 band-diagonal matrix



Listing such large matrices in Scilab is quite
confusing, because the data are wrapped and
shown a set of columns each time. Cleverly,
Scilab asks you if you want to continue to watch
all this mess. Press "N" to stop the listing.
Therefore we have to work only with the
variables A and B, remembering always to add
the semicolon ";" at the end of each statement,
in order to suppress the video output.




As we can see, in a spreadsheet, the big matrix examination works better.
Foxes Team
Foxes Team Pagina 5 20/08/2007
The Format-Trap
Both Excel and Scilab work with an internal maximum precision digits but they usually visualize the
result in different format.
In Excel the number of visualized decimals changes with the cell width.
In Scilab the standard visualized decimals is 7. In addition the exponential format is, for example
6.106D-16, while Excel shows 6.106E-16.

Beware that when we use the Scilab 4.1 function clipboard(), the exported precision always
depends by the decimals visualized. For changing in Scilab the visualized precision use the
format() command, example format(22);
Tip. for extracting always the maximum precision we have to set the scientific format('e',22)



Dimension limit
The maximum exportable dimension into Scilab is about 30,000 cells, corresponding about to a
square matrix of 170x170. If you overcome this limit, probably you will get the following message

!--error 26
too complex recursion! (recursion tables are full))
in execstr instruction called by :
at line 15 of function evstr called by :
A=evstr(clipboard('paste'));

warning: stack problem..., cleared

Exporting into Excel, instead, does not have this limit. You can successfully export matrices up to
250x250 without particular problems, apart the clipboard copying time that may take a while (20-40
sec)



Foxes Team
Foxes Team Pagina 6 20/08/2007

Excel_Scilab_IO.xla is freeware. Have fun with it

Augost 2007

You might also like