Hello and Happy new Year to all guys.
I came from world of matlab, and before one year started to code in java. I'm in countering problem that might be easy but bear with me please! here's the code of matlab: state is a variable of 3d array which its size: 2x4x64. state value is:(that's what I get on the editor of matlab)
state(:,:,1) =
1 0 0 0
2 0 1 1
state(:,:,2) =
3 0 1 0
4 0 0 1
state(:,:,3) =
5 0 1 1
6 0 0 0
state(:,:,4) =
7 0 0 1
8 0 1 0
state(:,:,5) =
9 0 1 1
10 0 0 0
state(:,:,6) =
11 0 0 1
12 0 1 0
state(:,:,7) =
13 0 0 0
14 0 1 1
state(:,:,8) =
15 0 1 0
16 0 0 1
state(:,:,9) =
17 0 0 0
18 0 1 1
state(:,:,10) =
19 0 1 0
20 0 0 1
state(:,:,11) =
21 0 1 1
22 0 0 0
state(:,:,12) =
23 0 0 1
24 0 1 0
state(:,:,13) =
25 0 1 1
26 0 0 0
state(:,:,14) =
27 0 0 1
28 0 1 0
state(:,:,15) =
29 0 0 0
30 0 1 1
state(:,:,16) =
31 0 1 0
32 0 0 1
state(:,:,17) =
33 0 0 1
34 0 1 0
state(:,:,18) =
35 0 1 1
36 0 0 0
state(:,:,19) =
37 0 1 0
38 0 0 1
state(:,:,20) =
39 0 0 0
40 0 1 1
state(:,:,21) =
41 0 1 0
42 0 0 1
state(:,:,22) =
43 0 0 0
44 0 1 1
state(:,:,23) =
45 0 0 1
46 0 1 0
state(:,:,24) =
47 0 1 1
48 0 0 0
state(:,:,25) =
49 0 0 1
50 0 1 0
state(:,:,26) =
51 0 1 1
52 0 0 0
state(:,:,27) =
53 0 1 0
54 0 0 1
state(:,:,28) =
55 0 0 0
56 0 1 1
state(:,:,29) =
57 0 1 0
58 0 0 1
state(:,:,30) =
59 0 0 0
60 0 1 1
state(:,:,31) =
61 0 0 1
62 0 1 0
state(:,:,32) =
63 0 1 1
64 0 0 0
state(:,:,33) =
1 1 1 1
2 1 0 0
state(:,:,34) =
3 1 0 1
4 1 1 0
state(:,:,35) =
5 1 0 0
6 1 1 1
state(:,:,36) =
7 1 1 0
8 1 0 1
state(:,:,37) =
9 1 0 0
10 1 1 1
state(:,:,38) =
11 1 1 0
12 1 0 1
state(:,:,39) =
13 1 1 1
14 1 0 0
state(:,:,40) =
15 1 0 1
16 1 1 0
state(:,:,41) =
17 1 1 1
18 1 0 0
state(:,:,42) =
19 1 0 1
20 1 1 0
state(:,:,43) =
21 1 0 0
22 1 1 1
state(:,:,44) =
23 1 1 0
24 1 0 1
state(:,:,45) =
25 1 0 0
26 1 1 1
state(:,:,46) =
27 1 1 0
28 1 0 1
state(:,:,47) =
29 1 1 1
30 1 0 0
state(:,:,48) =
31 1 0 1
32 1 1 0
state(:,:,49) =
33 1 1 0
34 1 0 1
state(:,:,50) =
35 1 0 0
36 1 1 1
state(:,:,51) =
37 1 0 1
38 1 1 0
state(:,:,52) =
39 1 1 1
40 1 0 0
state(:,:,53) =
41 1 0 1
42 1 1 0
state(:,:,54) =
43 1 1 1
44 1 0 0
state(:,:,55) =
45 1 1 0
46 1 0 1
state(:,:,56) =
47 1 0 0
48 1 1 1
state(:,:,57) =
49 1 1 0
50 1 0 1
state(:,:,58) =
51 1 0 0
52 1 1 1
state(:,:,59) =
53 1 0 1
54 1 1 0
state(:,:,60) =
55 1 1 1
56 1 0 0
state(:,:,61) =
57 1 0 1
58 1 1 0
state(:,:,62) =
59 1 1 1
60 1 0 0
state(:,:,63) =
61 1 1 0
62 1 0 1
state(:,:,64) =
63 1 0 0
64 1 1 1
%%%%%%%%%%%%%%%%%%%
revealed =[1 0];
tmp=[0,0];
for m=1:2
tmp[1]=sum(abs(state(l, 3:4 ,j)-revealed)) % here state(m, 3:4 ,j) is actually the 3rd and 4th columns substracting from them the array revealed at every row (m=1, 2) of given j.
end
so at the end it returns tmp.
to who doesn't understand matlab is that there's an array state with size 2x4x64 and state(l, 3:4 ,j) gives me the two columns values according to j and then we subtract the array revealed from then and we do afterwards abs and then sum to the array result. for example: state (m, 3:4 , 1) . J=1 gives me [0 0] and [1 1] for m=1 , m=2 at third and 4th columns. so at every m I subtract revealed [1 0] from the two value of third columns and 4th columns values according to m. so here at m=1 we have [0 0] so [0 0] - revealed => [0 0]-[1 0] => [-1 0] and we do abs([-1 0]) so we get [1 0] and then we do sum which it's 1+0 => 1. At m=1 we get [1 1] so [1 1]-[1 0] => [1 0] we do abs on this array => [1 0] and then afterwards we do sum 1+0 => 1 .
I'm trying to do the same thing / same concept in java (to convert this code matlab to java) . so what I've done is this:
int[64][2][4] state=
{
{{ 1 , 0 , 0 , 0},
{ 2 , 0 , 1, 1 }},
{{ 3 , 0 , 1 , 0},
{4 , 0 , 0 , 1}},
{{ 5 , 0 , 1 , 1},
{6 , 0 , 0 , 0}},
{{ 7 , 0 , 0 , 1},
{ 8 , 0 , 1 , 0 }}
{ {9 ,0 , 1 , 1},
{10 , 0 , 0 , 0}},
{ { 11 , 0 , 0 , 1},
{12 , 0 , 1 , 0}},
{ { 13 , 0 , 0 , 0},
{14 , 0 , 1 , 1}},
{ { 15 , 0 , 1 , 0},
{ 16 , 0 , 0 , 1} },
{{17 , 0 , 0 , 0},
{18 , 0 , 1 , 1 }},
{{19 , 0 , 1 , 0},
{20 , 0 , 0 , 1}},
{{21 , 0 , 1 , 1},
{ 22 , 0 , 0 , 0}},
{ { 23 , 0 , 0, 1} ,
{24 , 0 , 1 , 0}},
{ {25 , 0 , 1 , 1},
{26 , 0 , 0 , 0}},
{ {27 , 0 , 0 , 1},
{28 , 0 , 1 , 0}},
{{29 , 0 , 0 , 0},
{30 , 0 , 1 , 1}},
{{ 31 , 0 , 1 , 0},
{32 , 0 , 0 , 1}},
{ { 33 , 0 , 0 , 1},
{34 , 0 , 1 , 0} },
{{35 , 0 , 1 , 1},
{36 , 0 , 0 , 0}},
{{ 37 , 0 , 1 , 0},
{38 , 0 , 0 , 1}},
{{39 , 0 , 0 , 0},
{ 40 , 0 , 1 , 1}},
{{41 , 0 , 1 , 0},
{ 42 , 0 , 0 , 1}},
{{ 43 , 0 , 0 , 0},
{ 44 , 0 , 1 , 1}}
{45 , 0 , 0 , 1},
{46 , 0 , 1 , 0} },
{ { 47 , 0 , 1 , 1 },
{ 48 , 0 , 0 , 0 } },
{{ 49 , 0 , 0 , 1 },
{ 50 , 0 , 1 , 0 }},
{ { 51 , 0 , 1 , 1 },
{52 , 0 , 0 , 0} },
{ { 53 , 0, 1 , 0 },
{54 , 0 , 0 , 1} },
{ { 55 , 0 , 0 , 0 },
{ 56 , 0 , 1 , 1} },
{ {57 , 0 , 1 , 0},
{58 , 0 , 0 , 1} },
{ { 59 , 0 , 0 , 0 },
{ 60 , 0 , 1 , 1} },
{ { 61 , 0 , 0 , 1 },
{ 62 , 0 , 1 , 0} },
{ { 63 , 0 , 1 , 1},
{ 64 , 0 , 0 , 0 } },
};
public class GlobalMember
{
int[] revealed =[1 0];
int[] tmp= {0,0};
for(int j=0 ; j<64 ; j++)
{ for (int m = 0 ; l < 2 ; l++)
{
tmp[l] =
IntStream.of((Math.abs(state[m, 3 : 4, j] - revealed))).sum();
//note that I always just check 3rd and 4th columns values which
//they are implicitly an array with two element at every row of
//the two rows at every j(j is range from 0 to 64).
}
}
}
but it sounds Im missing something and it doesn't compile at all, could anyone please help me how do I implement this code matlab in java? I mean to implement the same concept of matlab code in java.
Im struggling this about one week and I didn't understand where's exactly the problem.
thanks alot.