Satimage Previous | Next
Manipulate and display data
Home Documentation Smile Smile Tutorial Write a data visualization script Manipulate and display data  
The sample data files
The examples below process tabulated ASCII data files. You will find such files in the folder /Applications/Smile/SmileLab examples/Sample data files/ (which comes installed with Smile full edition).
Extracting data from an ASCII data file
Suppose that we must process ASCII files which contain columns of values separated by tab, where the first line is a header to discard. First we use the extractcolumn verb to extract the data. Then we create a new curve (it comes empty, no formula, no data), and finally we load our data into the curve, namely by providing the curve's xdata and ydata properties with lists of numbers.
set f to (navchoose file without multiple files) as alias -- you are asked to select a file
set {x, y} to extractcolumn {1, 2} in f skipping 1 as array of real -- returns a list of two arrays of real
set w to make new graphic window
set v to make new plot view at w
set c to make new curve at v
set xdata of c to x
set ydata of c to y
draw w


Import script
The first line opens a dialog which prompts you to select an ASCII data file: select one in /Applications/Smile/SmileLab examples/Sample data files/.
Working with data
Suppose now that we want to extract three columns, in order to plot two curves. This is now not much harder than copy-paste. Here we experiment an alternate construction, with properties, to set properties at the time an object is created.
set f to (navchoose file without multiple files) as alias -- you are asked to select a file
set {x, y1, y2} to extractcolumn {1, 2, 3} in f skipping 1 as array of real -- returns a list of three arrays of real
set w to make new graphic window
set v to make new plot view at w
set c1 to make new curve at v with properties {xdata:x, ydata:y1}
set c2 to make new curve at v with properties {xdata:x, ydata:y2}
draw w


Import script
Probably we will want to make computations with the columns. The verb for that is evalformula. evalformula expects an expression, where you use any variable name which suits you, and a with parameter, where you specify what arrays or numbers should be substituted to the variables in the expression.
set f to (navchoose file without multiple files) as alias -- you are asked to select a file
set {x, y1, y2} to extractcolumn {1, 2, 3} in f skipping 1 as array of real -- returns a list of three arrays of real
set y to evalformula "a + 2*sin(b)" with {a:y1, b:y2}
set w to make new graphic window
set v to make new plot view at w
set c to make new curve at v with properties {xdata:x, ydata:y}


Import script
More commands are available to handle arrays and for computations. The numerical environment available is described in The scientific environment.
Copyright ©2008 Paris, Satimage