Go to the previous, next section.
Plot vectors may be generated in several ways:
read
command The file is expected to be an ASCII file of columns
of numbers (separated by spaces or commas). You define the file to
SM using the data
command, and associate a column or row
of numbers with a SM vector using the read
command.
Example: Say I have a file named test.dat with the following data in it:
1 2 3 5.6 10 3 6 8 2.3 11 5 8 2 7.7 12 7 9 4 9.3 13 9 3 1 4.8 14Then the commands to issue to SM to get the data into the program are:
data test.dat read x 1 read y 2(or
read { x 1 y 2 2
).
In the last 2 commands I have told SM to read the values in
column 1 of the file test.dat, and assign them to a vector named x,
and read the values in column 2 of the file and assign them to a
vector named y. I could read any of the other columns in as well, of
course, and assign them to vectors. And I can name the vectors
whatever I like, as long as the name consists of the characters
a-z,A-Z,0-9, and _ (underscore). I can also read a row from the
file, instead of a column, by saying
read row x 1Note that the vector is defined by the read command. But I can redefine it whenever I wish, and change the size. The only point to remember is that when you redefine the vector, the old values are overwritten.
A final point to note about defining
vectors from files is that you can skip over lines in the file with
the lines
command. lines
defines which lines in the file
you want to read. A limitation of lines
is that you may only
define one set of lines to read; that is, if you had a 30 line file,
and wanted to read lines 3-9 and 15-30, you couldn't (well, you could,
but you'd have to make clever use of the method of defining vectors
which is discussed in the next subsection, or make lines 10-14
each begin with a #).
set
command. This command has a number of forms:
set numlist = { 2 3 4 5 6 7 8 9 27 2
set ylist = sqrt(numlist) + numlist/3.1the allowed arithmetic operators are
sin,
cos, tan, acos, asin, atan, atan2, abs, int, lg, exp, ln, sqrt, concat,
**, +, -, *,
and /
, where lg
is
, ln
is
, int
takes the integer part, and concat
concatenates
two vectors.
set x = 0,PI,PI/16 set y = 0,10,0.1(PI is a constant defined for you by SM, but you can also define your own scalar variables, as will be described in a later section of this tutorial)
do
loop:
set y = 1,50 ... do i=0,100,2 { set y[$i] = $i**2 2(Note Well that vector elements are numbered starting from 0)
spline
command. This fits a
spline function to a previously defined pair of vectors, and
evaluates it at the points given in a third vector, to produce a
fourth vector for you.
set x = 0, 2 * PI, PI/4 set y = sin(x) set xx = 0, 2 * PI, PI/32 spline x y xx yyThis will fit a spline to the curve y vs x, at the points 0, PI/32, PI/16, 3 * PI/32,... (i.e. the points in the xx vector), and the spline values will be stored in the vector yy.
cursor
command. If you type the command
cursor a bthen a cursor will be displayed on the screen, and to the
spline
command.
This will take a horizontal slice through the image.
If you do not give a filename, the vectors are printed to the terminal.
Go to the previous, next section.