Sorry for the most basic of questions. How would I find the positions of a list of elements which are empty, for example I have the list
a = {1, 2, {}, {}, 3, 5};
and I want to find the indices of the empty elements.
If you want to find the position of something in a given expression, you should use Position
.
In this example, you could simply write:
Position[{1, 2, {}, {}, 3, 5}, {}]
(*{{3}, {4}}*)
I have to mention that this not the whole power of Position
: the second parameter of Position
can be a "pattern"(which may be not known by a matlab coder:)), look up the doc for more imformation.
Position[{1, 2, {}, {}, 3, 5}, {}]
yields{{3}, {4}}
$\endgroup${}
usingCases[{1, 2, {}, {}, 3, 5}, Except[{}]]
. $\endgroup$DeleteCases[{1, 2, {}, {}, 3, 5}, {}]
. $\endgroup$