how to add anew column to the table using MATLAB

3 views (last 30 days)
I have Fatures data of 30*5 of size.I would like to add a column to the table as "class" and In that class every 10 rows has to named differently.First 10 rows as "Helathy' then 11 to 20 as "Myopathy" and 21 to 30 as "Neuropathy".
X=randi(10,30,5);
X=arry2table(X,'variableNames',{'feat1','feat2',feat3',feat4','feat5'};
Now I need to add a column to the table (values as taken as example) so the resultatnt must be

Accepted Answer

Stephen23
Stephen23 on 17 Mar 2022
M = randi(10,30,5);
T = array2table(M,'variableNames',{'feat1','feat2','feat3','feat4','feat5'})
T = 30×5 table
feat1 feat2 feat3 feat4 feat5 _____ _____ _____ _____ _____ 9 9 2 1 3 6 2 10 2 3 9 2 1 3 1 9 5 4 1 3 2 1 4 6 8 8 10 7 10 3 7 10 6 7 9 5 9 8 3 7 7 7 7 6 2 8 9 3 7 4 1 1 2 7 8 2 5 5 2 3 3 2 1 8 10 5 2 4 7 7 10 4 1 2 4 8 3 9 4 8
T.Class = repelem(["Healthy";"Myopathy";"Neuropathy"],10,1)
T = 30×6 table
feat1 feat2 feat3 feat4 feat5 Class _____ _____ _____ _____ _____ __________ 9 9 2 1 3 "Healthy" 6 2 10 2 3 "Healthy" 9 2 1 3 1 "Healthy" 9 5 4 1 3 "Healthy" 2 1 4 6 8 "Healthy" 8 10 7 10 3 "Healthy" 7 10 6 7 9 "Healthy" 5 9 8 3 7 "Healthy" 7 7 7 6 2 "Healthy" 8 9 3 7 4 "Healthy" 1 1 2 7 8 "Myopathy" 2 5 5 2 3 "Myopathy" 3 2 1 8 10 "Myopathy" 5 2 4 7 7 "Myopathy" 10 4 1 2 4 "Myopathy" 8 3 9 4 8 "Myopathy"

More Answers (0)

Categories

Find more on Tables in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!