IamTrent
IamTrent

Reputation: 395

How to check if all cell values are equal to zero

I'm having difficulty checking whether all the cell values are zero. I've been looking around and can't find anything to match the array version.

My code:

handles.CheckFinger = cell(1,5);
handles.CheckFinger = [0 0 0 0 0];

if all(handles.CheckFinger == 0)
    msgbox('No fingers selected for recording.')
end

My error:

Undefined operator '==' for input arguments of type 'cell'

Upvotes: 1

Views: 558

Answers (2)

zdim
zdim

Reputation: 66873

For one, it does work for me as it stands.

However: you need to address the cells, not the array itself

if all(handles.CheckFinger(:) == 0)
    msgbox('No fingers selected for recording.')
end

Or, in this case simply

if handles.CheckFinger(:) == 0
    msgbox('No fingers selected for recording.')
end

Upvotes: 1

IamTrent
IamTrent

Reputation: 395

I'm not sure why it was working for others and not myself but I managed to produce a work around.

numericVector = cell2mat(handles.CheckFinger);

if all(numericVector == 0)
    msgbox('No fingers selected for recording.')
end

I'm using Matlab 2016a, not sure if this has anything to do with it.

Upvotes: 1

Related Questions