PHPExcel

# Source for file tile.php

Documentation is available at tile.php

1. <?php
3. include "../Matrix.php";
5. /**
6. * Tiling of matrix X in [rowWise by colWise] dimension. Tiling
7. * creates a larger matrix than the original data X. Example, if
8. * X is to be tiled in a [3 x 4] manner, then:
9. *
10. * / \
11. * | X X X X |
12. * C = | X X X X |
13. * | X X X X |
14. * \ /
15. *
16. * @param X Matrix
17. * @param rowWise int
18. * @param colWise int
19. * @return Matrix
20. */
22. function tile (&$X, $rowWise, $colWise){
24. $xArray = $X->getArray();
25. print_r ($xArray);
27. $countRow = 0;
28. $countColumn = 0;
30. $m = $X->getRowDimension();
31. $n = $X->getColumnDimension();
33. if( $rowWise<1 || $colWise<1 ){
34. die("tile : Array index is out-of-bound.");
35. }
37. $newRowDim = $m*$rowWise;
38. $newColDim = $n*$colWise;
40. $result = array();
42. for($i=0 ; $i<$newRowDim; ++$i) {
44. $holder = array();
46. for($j=0 ; $j<$newColDim ; ++$j) {
48. $holder[$j] = $xArray[$countRow][$countColumn++];
50. // reset the column-index to zero to avoid reference to out-of-bound index in xArray[][]
52. if($countColumn == $n) { $countColumn = 0; }
54. } // end for
56. ++$countRow;
58. // reset the row-index to zero to avoid reference to out-of-bound index in xArray[][]
60. if($countRow == $m) { $countRow = 0; }
62. $result[$i] = $holder;
64. } // end for
66. return new Matrix($result);
68. }
71. $X =array(1,2,3,4,5,6,7,8,9);
72. $nRow = 3;
73. $nCol = 3;
74. $tiled_matrix = tile (new Matrix($X), $nRow, $nCol);
75. echo "<pre>";
76. print_r ($tiled_matrix);
77. echo "</pre>";
78. ?>

Documentation generated on Fri, 12 Oct 2012 00:18:12 +0200 by phpDocumentor 1.4.4