Create new columns in tale adding prior data

1 Ansicht (letzte 30 Tage)
DavidL88
DavidL88 am 16 Mär. 2022
Kommentiert: DavidL88 am 7 Apr. 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?

Antworten (1)

Cris LaPierre
Cris LaPierre am 16 Mär. 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 Kommentare
Cris LaPierre
Cris LaPierre am 28 Mär. 2022
What about this can't be automated?
DavidL88
DavidL88 am 7 Apr. 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?

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Tables finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by