I want to convert my triangular matrix into a vector.
Let's say I have 7x7 lower triangular matrix. Something like this:
0 0 0 0 0 0 1
0 0 0 0 0 2 3
0 0 0 0 4 5 6
0 0 0 7 8 9 10
0 0 11 12 13 14 15
0 16 17 18 19 20 21
22 23 24 25 26 27 28
And I need to convert this matrix into a vector ignoring zeros. So, the result should be:
[1 2 3 4 5 6 7 8 9 10 11 12 13 14 ... 28]
I have already made a matrix by the following code:
int specMas[][] = new int[7][7];
Random rand = new Random();
int i, j;
for(j = 6; j > -1; j--) {
for(i = 6; i > 5-j; i--) {
specMas[i][j] = rand.nextInt(-100, 101);
}
}
for (i=0; i<7; i++) {
for (j=0; j<7; j++)
System.out.print(specMas[i][j]);
System.out.println();
}
But I don't really get how to convert that into a vector. Can you please explain me how?
