# Extracting data from a table that has cells in cells

2 views (last 30 days)
Maxime Lehman on 20 Oct 2020
Commented: Maxime Lehman on 20 Oct 2020
I have a table with 768 rows x 3 columns. I'm trying to exclude rows based on the values of the third column. Here is the beginning of the table:
'date' 'id' 'action'
'20200120' 5 276x1 double
'20200120' 4 1264x1 double
As you can see, each cell of the third column (action) actually contains hundreds of values.
These values are either 0 or 1, based on whether an action is performed (1) or not (0), each row of that cell corresponding to a specific timepoint.
I only want to know which individuals (id) performed any action at all, i.e. for the individual 5, among the 276 values of its 'action' cell, is there at least one value that isn't 0 (that is 1)?
Any help would be greatly appreciated. Returning a single average value for each 'action' cell would be one way but I don't know how to

Stephen Cobeldick on 20 Oct 2020
Edited: Stephen Cobeldick on 20 Oct 2020
>> S(1).date = '20200120';
>> S(2).date = '20200120';
>> S(1).id = 1;
>> S(2).id = 2;
>> S(1).action = [0;0;0;1;0];
>> S(2).action = [0;0;0];
>> T = struct2table(S)
T =
date id action
__________ __ ____________
'20200120' 1 [5x1 double]
'20200120' 2 [3x1 double]
>> T.out = cellfun(@any,T.action) % <- try this
T =
date id action out
__________ __ ____________ _____
'20200120' 1 [5x1 double] true
'20200120' 2 [3x1 double] false

#### 1 Comment

Maxime Lehman on 20 Oct 2020
Works great, thank you very much Stephen!