2015-10-30 58 views
-1

我想重新品嚐來自2×2 data一個二維數組在4x4 newdata重新取樣二維數組4×4

原文出處二維數組data

enter image description here

我要尋找一個在newdata

enter image description here

到目前爲止,我已經嘗試了下面;

public class Test { 
    static int[][] data = new int[2][2]; 
    static int[][] newdata = new int[4][4]; 

public static void main(String[] args) { 

    data[0][0] = 00; 
    data[0][1] = 01; 
    data[1][0] = 10; 
    data[1][1] = 11; 

for (int i = 0; i < 2; i++) { 

     for (int j = 0; j < 2; j++) { 

// I NEED LOGIC HERE TO FILL newdata 2D ARRAY as a re-sampled output 

     } 
    } 

} 

} 

實現可以使用任何語言,例如C++,PHP,C#,JAVA等

任何幫助表示讚賞,在此先感謝。

+0

你嘗試過在你的邏輯做任何事,因爲你的嘗試只涉及初始化第一陣列 – SomeJavaGuy

+0

@KevinEsche我試圖在每一個指標的迭代創建邏輯,但不能得到我想要的。 – Alyas

回答

1

更改您的循環來:

 for (int k = 0; k < 4; k++) 
     { 
      for (int l = 0; l < 4; l++) 
      { 
       newdata[k][l] = data[k/2][l/2]; 
      } 
     } 
+2

外部2'''for'''語句(i和j)是多餘的。 – saka1029

+0

你是正確的saka!謝謝。我編輯 –

+0

謝謝@EmmanuelDURIN它像一個魅力工作! – Alyas