next up previous contents
Next: ASCII files Up: Files: reading and writing Previous: Files: reading and writing   Contents

Scilab variables

We can save the variables we use in the following way

-->a = rand(3,3)
 a  =
 
!   0.2113249    0.3303271    0.8497452 !
!   0.7560439    0.6653811    0.6857310 !
!   0.0002211    0.6283918    0.8782165 !
 
-->save a
 
-->clear
 
-->a
  !--error     4 
undefined variable : a                       
 
 
-->load a
 
-->a
 a  =
 
!   0.2113249    0.3303271    0.8497452 !
!   0.7560439    0.6653811    0.6857310 !
!   0.0002211    0.6283918    0.8782165 !
If we look at the directory (you can locate where you are by using `pwd') you will see that a file called `a' appeared. This file allows the recovering of `a' as long as it is not deleted. We can also assign a name with the instruction `save('namefile', variable)' or even save all the variables with `save('namefile')'. To recover the variables, we can use the command `load' that allows us to recover some or all the variables included in the file.

-->a = 1                       // creation of a
 a  =
 
    1.  
 
-->b = 7:-1:5                  // creation of b 
 b  =
 
!   7.    6.    5. !
 
-->save('variables')           // saves a and b in `variables'
 
-->clear                       // clears all variables
 
-->a                           // a can not be found (it has been erased)
  !--error     4  
undefined variable : a                       
  
-->b                           // b can not be found (it has been erased)
  !--error     4 
undefined variable : b                       
 
-->load('variables','b')       // recovers b from `variables'
 
-->b                           // prints b
 b  =
 
!   7.    6.    5. !           
 
-->a                           // a can not be found (not recovered)
  !--error     4 
undefined variable : a 
-->clear                       // clears all variables
 
-->load('variables')           // recovers all variables
 
-->a                           // prints a
 a  =
 
    1.  
 
-->b                           // prints b
 b  =
 
!   7.    6.    5. !
Notice that `save' and `load' do not need any other command to open or close the file. They are easy to use and they can be used once we get data from other sources to maintain the intermediate steps of our work. We can create a directory specifically dedicated to the current work and all the variables are stored with their names in such a way that they can be recovered afterwards. There is a command useful to navigate in the directory tree of your disk


-->filename = xgetfile()
This command makes appear a file window when you can find any file and select it. The name of the selected file (with the absolute address) is assigned to a string that can be employed afterwards. If you do not select any file, it returns an empty string.

There are also another two functions that allows read and write matlab (version 4) variables: `mtlb_load' and `mtlb_save'.


next up previous contents
Next: ASCII files Up: Files: reading and writing Previous: Files: reading and writing   Contents
j 2003-01-23