I want to make a table with following data,
$a_{ij} = b_{ij}$ for $1\le i <j\le n-2$ and $|i-j| \ge 2$.
Try
n = 7;
Table[If[Abs[i - j] > 2, a[i, j] == b[i, j], Nothing], {i, 1,n - 2}, {j, i+1, n - 2}] // Flatten
(*{a[1, 4] == b[1, 4], a[1, 5] == b[1, 5], a[2, 5] == b[2, 5],a[4, 1] == b[4, 1], a[5, 1] == b[5, 1], a[5, 2] == b[5, 2]}*)
a,b
it's difficult to distinguish non-zero entries!
$\endgroup$
Commented
Jul 25, 2019 at 13:22
0
or Null
entries that are appearing without referring to a
or b
..
$\endgroup$
Commented
Jul 25, 2019 at 13:33
Nothing
inside If is what you're looking for. My answer is edited.
$\endgroup$
Commented
Jul 25, 2019 at 13:39
Try
n = 7;
t=Table[a[i, j] == b[i, j], {j, 1,n - 2}, {i, 1,j - 2}]/.{}->Sequence[]
giving
{{a[1,3]==b[1,3]},
{a[1,4]==b[1,4],a[2,4]==b[2,4]},
{a[1,5]==b[1,5],a[2,5]==b[2,5],a[3,5]==b[3,5]}}
And you can use Flatten
on that if you don't want the extra {}
{}->Sequence[]
part? Also can I generalize this to different conditions, say, |i-j| >= 5
or something..
$\endgroup$
Commented
Jul 25, 2019 at 13:31
/.{}->Sequence[]
you will see that it leaves in "empty" rows where none of the items match both your conditions, so I used that "trick" to discard empty rows. For your generalized conditions try n = 12; t=Table[ a[i, j] == b[i, j], {j, 1,n - 2}, {i, 1,j - 5}]/.{}->Sequence[]
$\endgroup$