In reply to KAUSHIK BHATTACHARJE.

Yes. If the condition inside the LOC function is not satisfied, then the LOC function returns an empty matrix. When you try to use idx as a subscript, the error occurs. You can read about this situation and how to handle it correctly in the article "Beware the naked LOC."