Create new columns in tale adding prior data

1 vue (au cours des 30 derniers jours)
DavidL88
DavidL88 le 16 Mar 2022
Commenté : DavidL88 le 7 Avr 2022
I have a table (sample attached) summarising neural activity; either 1 or -1. The rest are blanks. The first two columns relate to the test. The third column onwards is a summary of the activity. There are 68 of these columns. These 68 regions are part of larger regions denoted by first part of text within each column (LF, LC, LT etc). The number of columns per region differs. I want to create a new series of columns that adds the aboslute value of these sub regions so I'll have columns with the value of the overall region ie LF_1... = 1, LF_2... = -1, LF_3... = 1 Resulting column LF will be 3 for that row. How can I do this? Is there a way to automatically recognise the first letters prior to the first "_" to create a new column?

Réponses (1)

Cris LaPierre
Cris LaPierre le 16 Mar 2022
Columns in a table are variables. Here, you want to just create a 'new' variable, and set it equal to the sum of the existing variables.
% create a same table
LF_1 = 1;
LF_2 = -1;
LF_3 = 1;
T = table(LF_1,LF_2,LF_3)
T = 1×3 table
LF_1 LF_2 LF_3 ____ ____ ____ 1 -1 1
% Create a new variable LF in the table as sum of LF_1-3
T.LF = abs(T.LF_1) + abs(T.LF_2) + abs(T.LF_3)
T = 1×4 table
LF_1 LF_2 LF_3 LF ____ ____ ____ __ 1 -1 1 3
  3 commentaires
Cris LaPierre
Cris LaPierre le 28 Mar 2022
What about this can't be automated?
DavidL88
DavidL88 le 7 Avr 2022
Thanks. Is there a way to recognise groups of variables/columns based on the letters prior to a "_"? So recognise group LF from LF_1, LF_2, LF_3. Rather than writing a line of code for each group - LF, RF, LPF, etc is there a code that would recognise these groupings?

Connectez-vous pour commenter.

Catégories

En savoir plus sur Tables dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by