I need to compare two matrices with the same number of columns but a different number of rows (please see an example of Matrices A and B). I would like to know how I can compare the second column of the first matrix with the second column of the second matrix and if there were any equal value substitute the associated array in the first column of the first matrix with the associated array in the first column of the second matrix and restore the first Matrix. For example
A = {{1, 2, 3, 5}, {4, 5, 6, 8}, {7, 8, 9, 3}, {3, 56, 8, 2}, {4, 5, 6,
8}}
B = {{6, 7, 9, 1}, {2, 5, 0, 8}, {1, 2, 3, 7}, {34, 56, 78, 56}}
Considering that A[[2,2]]=B[[2,2]]=5 and A[[4,2]]=B[[4,2]]=56, after applying the above condition, the Matrix A should change to:
ANew= {{1, 2, 3, 5}, {2, 5, 6, 8}, {7, 8, 9, 3}, {34, 56, 8, 2}, {4, 5, 6,
8}}
General case:
What if the same elements were located in different rows (for example):
A = {{1, 2, 3, 5}, {4, 5, 6, 8}, {7, 8, 9, 3}, {3, 56, 8, 2}, {4, 5,
6, 8}};
B = {{6, 7, 9, 1}, {2, 5, 0, 8}, {1, 56, 3, 7}, {34, 42, 78, 56}};
In this case, considering that A[[2,2]]=B[[2,2]]=5 and A[[4,2]]=B[[3,2]]=56, after applying the above condition, the Matrix A should change to:
ANew= {{1, 2, 3, 5}, {2, 5, 6, 8}, {7, 8, 9, 3}, {1, 56, 8, 2}, {4, 5, 6,
8}}
A[[2,4]]=B[[2,4]]=8
, which are the elements in 2nd row and 4th column. $\endgroup$A
be modified if there multiple equivalent elements e.g.A[[2,2]]=A[[3,2]]=B[[1,2]]=B[[4,2]]=5
? Also, the question looks like a XY problem, what exactly are you trying to do? $\endgroup$