phdstudent
phdstudent

Reputation: 1144

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.

Upvotes: 1

Views: 174

Answers (1)

Daniel
Daniel

Reputation: 36710

You have to use the strcmp function:

strcmp(A,'QTR')

Upvotes: 5

Related Questions