"For loop" to perform statistical analysis /math on separate sets of columns of table

1 view (last 30 days)
I am trying to perform some data mining, cleaning and analysis on a set of data. I have imported my numerous excel files in the following format
(so their nomenclature can easily be used especially in for loops), to make a table "T_Joined".
FT{11} = readtable('TestM1FT1', 'Sheet', 1);
FT{12} = readtable('TestM1FT1', 'Sheet', 2); ..
I am now trying to create new columns in the table using values from existing columns of the table with column names "T_Joined.PSM1FT2", "T_Joined.PSM2FT3" etc. upon performing some math. I wrote the following 'for' loop because I will need to repeat this about 10 times.
for a=[2,3,4]
T_Joined.AvgFT{a} = (T_Joined.PSM1FT{a} + T_Joined.PSM2FT{a})./2;
end
However, the compiler returns:
"Error using tabular/numArgumentsFromSubscript (line 78)
Unrecognized table variable name 'PSM1FT'.
Error in XXX (line 71)
T_Joined.AvgFT{a} = (T_Joined.PSM1FT{b} + T_Joined.PSM2FT{b})./2;"
Looks like the right hand side of the way I used the variable a in the for loop - doesnt execute. I was wondering if I could get some assistance on rectifying this!

Accepted Answer

Walter Roberson
Walter Roberson on 29 Dec 2020
for a=[2,3,4]
T_Joined.("AvgFT"+a) = (T_Joined.("PSM1FT"+a) + T_Joined.("PSM2FT" +a) )./2;
end

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!