Search code examples
matlablogiccell-array

Logical Indexing Cell Array


I have a cell array with two types of strings: 'ANN' and 'QTR'.

I am trying to get a vector with ones if cell array equals 'QTR'.

Here's an example of what I am trying to do:

A = {'ANN';'ANN';'ANN';'ANN'; 'QTR'; 'ANN'; 'QTR'; 'QTR'; 'QTR'; 'QTR'};
logic1 = A == 'QTR'

However, this sort of notation doesn't seem to work well with cells. I have looked for workarounds, but did not manage to find any.

Any help would be much appreciated.


Solution

  • You have to use the strcmp function:

    strcmp(A,'QTR')