MATLAB: List all cells that match logical criteria

cell arrayslogical?

Hello,
I need help with logic that will extract the corresponding strings in column #2 if columns #1 is true (=1).
For ex: I have a 4×2 cell array with: [1] ‘13_dogs’ [] ‘24_dogs’ [1] ‘100_dogs’ [] ‘7_dogs’
And I would like a new cell array with: ‘13_dogs’ ‘100_dogs’
It would be a new 2×1 array after the condition of =1 is met.
Appreciate in advance!

Best Answer

>> C = {1,'13_dogs';[],'24_dogs';1,'100_dogs';[],'7_dogs'};
>> X = cellfun(@(a)isequal(a,1),C(:,1));
>> D = C(X,2);
Checking:
>> D{:}
ans = 13_dogs
ans = 100_dogs