Create new columns in tale adding prior data

2 次查看(过去 30 天)
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?

回答(1 个)

Cris LaPierre
Cris LaPierre 2022-3-16
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 个评论
DavidL88
DavidL88 2022-4-7
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?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Text Analytics Toolbox 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by