BayES BayES

B.4 Import, export and memory management

The following statements are used to clear items from memory, save or load workspaces, and import or export items from/to text files.



Syntax

Arguments and performed function



clear(A);

Clears item with id value A from memory. A could be any of the following data types:

  • matrix
  • dataset
  • model
  • structure
  • string

or the keywords:

  • all
  • matrices
  • datasets
  • models
  • structures
  • strings

The statement clear(all); clears all items from memory, while, for example, clear(matrices); clears all matrices from memory.



save(s);

Saves the current workspace (all items in memory) to the file specified by s.

  • s must be a string containing the directory, filename and extension of the file to be saved.
  • The path to the file specified in s can be absolute (eg. "C:/MyFiles/MyFolder/MyFile.bws") or relative to the current working directory (eg. "./MyFolder/MyFile.bws").



load(s);

Loads a previously saved workspace from the file specified by s to the current workspace. The current workspace must be empty for the operation to proceed.

  • s must be a string containing the directory, filename and extension of the file to be loaded.
  • The path to the file specified in s can be absolute (eg. "C:/MyFiles/MyFolder/MyFile.bws") or relative to the current working directory (eg. "./MyFolder/MyFile.bws").



D = import(s [, d ]);

D = webimport(s [, d ]);

D is a dataset constructed by reading the contents of the file or URL specified in s.

  • s must be a string specifying the directory, filename and extension of (in the case of import()) or the URL that points to (in the case of webimport()) the file which contains the data to be imported.
  • In the case of import(), the path to the file can be absolute (eg. "C:/MyFiles/MyFolder/MyFile.csv") or relative to the current working directory (eg. "./MyFolder/MyFile.csv").
  • d is the delimiter used in the data file to separate values and must be equal to one of the following strings:
    • ","
    • ";"
    • "t"

    The default value is comma (",") and is used for importing data from csv files. ";" and "t" can be specified to alter the default value separator to semicolon and tab, respectively.

  • The variables in the file specified by s must be organized in columns, with the first row containing the variable names.



export(id, s [, d]);

export(s1, s2 [, <options>]);

When used in the first format, export(id, s [, d]);, the function exports the item in memory with id value id to the file specified in s.

  • id must be the name of a dataset or matrix currently in memory (structures, models and strings cannot be exported).
  • s must be a string containing the directory, filename and extension of the file to which the data are to be exported
  • The path to the file specified in s can be absolute (eg. "C:/MyFiles/MyFolder/MyFile.csv") or relative to the current working directory (eg. "./MyFolder/MyFile.csv").
  • d is the delimiter used in the data file to separate values and must be a string with one of the following values:
    • ","
    • ";"
    • "t"

    The default value is comma (,) and is used for exporting data to the csv format. ; and \t can be specified to alter the default value separator to semicolon and tab, respectively.

  • When exporting a matrix, the values of the matrix are printed in the file specified in s. When exporting a dataset, the variable names are printed in the first row of the file, before printing the actual values of the variables.

When used in the second format, the function exports the graph contained in the figure window with title s1 to the file specified in string s2. The type of the exported graph (eps, png or jpeg) is determined by the extension of the file provided in s2.

  • s1 must be a string equal to the name appearing on the title bar of the figure window, the contents of which are to be exported.
  • s2 must be a string containing the directory, filename and extension of the file to which the graph will be exported.
  • The path to the file specified in s2 can be absolute (eg. "C:/MyFiles/MyFolder/MyGraph.eps") or relative to the current working directory (eg. "./MyFolder/MyGraph.eps").

The <options> argument allows setting the width and height of the exported figure, in pixels. For example, export([...],"width"=100,"height"=100); will set the width and height of the exported figure to 100 pixels. The default values for "width" and "height" are 400 and 250, respectively.



Share this content:
Facebook Twitter LinkedIn Email
© 2016–20 Grigorios Emvalomatis