Scusami, ti ringrazio per l'aiuto e non me ne volere, credevo che mi si abbozzasse uno pseudocodice e poi l'avrei adattato per la mia rappresentazione della matrice. Scusami ancora.Originariamente inviato da satifal
Scusa, fammi capire, posti una domanda ben precisa e dopo che qualcuno si sbatte per trovarti una soluzione dici "scusate tanto ho scherzato...in realtà mi serviva quest'altra cosa"?!?!?!?!?!?!![]()
Io ho provato a modificarla così:
Non riesco bene a capire getsubmatrix ed il tostring come lavorano. Mentre il setvalue non mi serviva proprio.codice:package lettura_mappa; import java.util.ArrayList; import javax.print.attribute.Size2DSyntax; public class Matrix { private ArrayList<ArrayList<Cella_base>> matrix = null; public Matrix() { } public Matrix(ArrayList<ArrayList<Cella_base>> matrix) { this.matrix = matrix; } public Matrix getSubMatrix(int row, int column, int width, int height) { try { int r0 = matrix.length - row > height ? height : matrix.length - row; int c0 = matrix.length - column > width ? width : matrix.length - column; String[][] m = new String[r0][c0]; for (int r = 0; r < m.length; r++) { for (int c = 0; c < m[0].length; c++) { m[r][c] = matrix[row + r][column + c]; } } return new Matrix(m); } catch (Exception e) { return new Matrix(); } } public Cella_base getValue(int row, int column) { //return matrix[row][column]; return (matrix.get(column)).get(row); } public int getRows() { try { return (matrix.get(0)).size(); } catch (Exception e) { return 0; } } public int getColumns() { try { return matrix.size(); } catch (Exception e) { return 0; } } @Override public String toString() { StringBuffer sb = new StringBuffer(""); try { for (int r = 0; r < matrix.length; r++) { sb.append("["); for (int c = 0; c < matrix[0].length; c++) { sb.append("[" + matrix[r][c] + "]"); } sb.append("]"); } } catch (Exception e) { sb.append("[]"); } return sb.toString(); } public static void main(String[] args) { String[][] matrix = { {"00", "01", "02", "03", "04"}, {"10", "11", "12", "13", "14"}, {"20", "21", "22", "23", "24"}, {"30", "31", "32", "33", "34"}, {"40", "41", "42", "43", "44"} }; Matrix m = new Matrix(matrix); int n = 2; int rLimit = (int) Math.ceil((double) m.getRows() / (double) n); int cLimit = (int) Math.ceil((double) m.getColumns() / (double) n); for (int r = 0, rr = 0; r < rLimit; r++, rr += n) { for (int c = 0, cc = 0; c < cLimit; c++, cc += n) { Matrix sm = m.getSubMatrix(rr, cc, n, n); System.out.println(sm); } } } }
Ti ringrazio ancora per l'aiuto.


Rispondi quotando