Return "c" and indices of a variable c[i,j] in Mathematica
Another possible way using Level
and Heads
.
Level[c[i, j], 1, Heads -> True]
(* {c, i, j} *)
A simple approach is
c[i, j];
{Head[%], %1[[1]], %[[2]]}
(* {c, i, j} *)
Slightly more generally, use
f[x_] := Join[{Head[x]}, List @@ x]
f[c[i, j]]
(* {c, i, j} *)
using pattern-matching/deconstruction
c[i, j] /. a_[b_, c_] -> {a, b, c}
or define your own function:
f[a_[b_, c_]]:={a, b, c}
f[ c[i, j] ]
{c, i, j}