VARIABLE = valueor, if you wish to assign a value to a subset of a matrix:
VARIABLE += value
...
VARIABLE[range] = valueLike in the C programming language, several assignment operators are possible.
VARIABLE[range] += value
...
Operator | Syntax | Operands |
Assignment | VARIABLE = value | Number, matrix, string, string array |
Increment | VARIABLE++ | Number, matrix |
Decrement | VARIABLE-- | Number, matrix |
Multiplication | VARIABLE *= value | Number, matrix |
Division | VARIABLE /= value | Number, matrix |
Addition | VARIABLE += value | Number, matrix, string, string array |
Subtraction | VARIABLE -= value | Number, matrix |
If the "+=" operator is applied to a string array, the string
at the right hand side of the statement will be appended to the string
array.
The assignment operator "=" can be used to write a matrix
as a FITS file. The syntax for doing this is 'filename'=matrix,
i.e. you assign a matrix to a filename, which is in single quotes. Note
that writing FITS files is also possible using the writefits
procedure.
var = 6 | creates a new variable named var and assigns a value of 6 |
'gauss.fits' = gauss(129, 129, 30) | writes a 2-dimensional gaussian to a disk file named gauss.fits |
var[100:200, *]++ | Increments elements 100 through 200 in the first dimension and all elements in the second dimension |
print sin(pi()) | prints out the sine of pi |
var = 2 + 3 * 5 | yields 17 |
var = (2 + 3) * 5 | yields 25 |
mvar = [1, sin(pi()), 3+5] | creates a 1-dimensional matrix with the values 1, 0, 8 |
nvar = [-3600:3600] / 10 | creates a 1D matrix with the values -360, -359.9, ..., 360 |
svar = ["test", "string"] | creates a string array with 2 elements |
print mvar[2] | prints the second element of mvar, which is 0 |
print svar[1] | prints out "test" |
print svar[2][strlen(svar[2])] | prints out the last character of the second element of svar, which is a "g" |
newvar = nvar[3601:3700] | creates a new matrix variable with 100 elements and assigns the values 0, 0.1, ..., 9.9 |
Operator | Syntax | Arguments | Return Value |
Exponentation | x ^ y | Number, Matrix | Number if both x and y are numbers
Matrix if either x or y is a matrix |
Multiplication | x * y | Number, Matrix | Number if both x and y are numbers
Matrix if either x or y is a matrix |
Matrix multiplication | x # y | Matrix or vector | Matrix |
Division | x / y | Number, Matrix | Number if both x and y are numbers
Matrix if either x or y is a matrix |
Modulus | x % y | Integer number | Integer number |
Addition | x + y | Number, Matrix | Number if both x and y are numbers
Matrix if either x or y is a matrix |
Number, String | String if either x or y is a string | ||
String, String array | String array if either x or y is a string array | ||
Subtraction | x - y | Number, Matrix | Number if both x and y are numbers
Matrix if either x or y is a matrix |
Operator | Syntax | Arguments | Return Value |
Not | !x | Boolean | Boolean |
Not equals | x != y | Number, String | Boolean |
Equals | x == y | Number, String | Boolean |
Greater than | x > y | Number, String | Boolean |
Greater or equal | x >= y | Number, String | Boolean |
Less than | x < y | Number, String | Boolean |
Less than or equal to | x <= y | Number, String | Boolean |
And | x && y | Boolean | Boolean |
Or | x || y | Boolean | Boolean |