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?
0 个评论
回答(1 个)
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)
% 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)
3 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Text Analytics Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!