Last active
May 5, 2016 18:35
-
-
Save malalanayake/76fb11719003b43c1eb5bb4409808c8c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ch.makery.address; | |
public class Repmat { | |
public static void main(String[] args) { | |
int[][] oldArray; | |
oldArray = new int[][] { { 1, 2, 4 }, { 5, 2, 1 } }; | |
int size = 4; | |
MyTest.printArray(oldArray); | |
int oldY = oldArray.length; | |
int oldX = oldArray[0].length; | |
int newArryHeight = oldY * size; | |
int newArryWidth = oldX * size; | |
int[][] current = new int[newArryHeight][newArryWidth]; | |
// Go through the new array length | |
for (int x = 0; x < current.length; x++) { | |
int indexY = 0; | |
// Loop up to the given size | |
for (int count = 0; count < size; count++) { | |
for (int k = 0; k < oldY; k++) { | |
int indexX = 0; | |
// Loop up to the given size | |
for (int z = 0; z < size; z++) { | |
for (int j = 0; j < oldX; j++) { | |
// Fill the new array from old values | |
current[indexY][indexX] = oldArray[k][j]; | |
indexX++; | |
} | |
} | |
indexY++; | |
} | |
} | |
} | |
Repmat.printArray(current); | |
} | |
public static void printArray(int[][] newArray) { | |
System.out.println("======================================"); | |
for (int i = 0; i < newArray.length; i++) { | |
for (int j = 0; j < newArray[0].length; j++) { | |
System.out.print(newArray[i][j]); | |
} | |
System.out.println(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment