Extracting data from a table that has cells in cells

3 visualizaciones (últimos 30 días)
Maxime Lehman
Maxime Lehman el 20 de Oct. de 2020
Comentada: Maxime Lehman el 20 de Oct. de 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

Respuesta aceptada

Stephen23
Stephen23 el 20 de Oct. de 2020
Editada: Stephen23 el 20 de Oct. de 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

Más respuestas (0)

Categorías

Más información sobre Dates and Time en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by