operator '==' not supported for operands of type 'cell'

642 views (last 30 days)
While there are some useful answers to this type of question, a lot of them are too advanced for me to understand/use as a beginning MATLAB student. I am trying to loop through rows of a table to find instances in which in a particular index is equal to something. Here is a picture of what my table looks like:
and I am interested in comparing when a subject has responded true or false to a certain verb ('smashed' is one of 3). My idea for doing this would be to make a for loop such as the following:
smashedFalseCounter = 0;
for i = 1:height(myTable)
if myTable.verb(i) == 'smashed'
if expTable2.response(i) == false
smashedFalseCounter = smashedFalseCounter + 1;
end
end
end
And I get the following error message:

Answers (1)

madhan ravi
madhan ravi on 4 Jun 2020
ismember(myTable.verb(i), 'smashed')
  1 Comment
madhan ravi
madhan ravi on 4 Jun 2020
Edited: madhan ravi on 12 Oct 2020
And by the way you don’t need a loop.
Counts = nnz(ismember(myTable.verb(myTable.Response == true), 'smashed'))

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!