File: MatrixIndexing.bf

package info (click to toggle)
hyphy 2.5.69%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 26,728 kB
  • sloc: cpp: 81,964; xml: 467; lisp: 341; python: 166; javascript: 117; sh: 106; makefile: 87; ansic: 86
file content (30 lines) | stat: -rw-r--r-- 1,490 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
fprintf (stdout, "\n1). Spawning a zero-populated 5x6 matrix and setting it's values to random numbers in [0,1].\n");
aMatrix = {5,6};
aMatrix = aMatrix ["Random(0,1)"];
fprintf (stdout, aMatrix, "\n");

fprintf (stdout, "\n2). Accessing a second-row third-column element and a random element.\n\n");
r = Random (0, Rows(aMatrix))$1;
c = Random (0, Columns(aMatrix))$1;
fprintf (stdout, "matrix[1][2]=", aMatrix[1][2], "\nmatrix[", r , "][" , c, "]=", aMatrix[r][c], "\n");

fprintf (stdout, "\n3). Accessing the fourth row.\n\n");
fprintf (stdout, "matrix[3][-1]=\n", aMatrix[3][-1],"\n");

fprintf (stdout, "\n4). Accessing the first column.\n\n");
fprintf (stdout, "matrix[-1][0]=\n", aMatrix[-1][0],"\n");

fprintf (stdout, "\n5). Populating a matrix template (below the diagonal).\n\n");
template={5,6};
template=template["_MATRIX_ELEMENT_ROW_>_MATRIX_ELEMENT_COLUMN_"];
fprintf (stdout, template ,"\n");

fprintf (stdout, "\n6). Extracting (by row) matrix elements using the template.\n\n");
fprintf (stdout, aMatrix[template] ,"\n");

fprintf (stdout, "\n7). Extracting a submatrix: top left corner at (1,1) - bottom right corner at (3,2).\n\n");
fprintf (stdout, "matrix[{{1,1}}][{{3,2}}]=\n", aMatrix[{{1,1}}][{{3,2}}],"\n");

fprintf (stdout, "\n8). Returning a matrix in which all elements are squared and above diagonal elements are further increased by 1.\n\n");
fprintf (stdout, "\n", aMatrix["_MATRIX_ELEMENT_VALUE_^2+(_MATRIX_ELEMENT_ROW_<_MATRIX_ELEMENT_COLUMN_)"],"\n");