How to Merge the cells and name?
17 views (last 30 days)
Show older comments
I have the data and I would like to name and merge.The above table the data i have, the below table the table i required.
1 Comment
Walter Roberson
on 6 Jul 2022
How does this differ from the previous similar questions you have posted on the topic?
Accepted Answer
Chunru
on 6 Jul 2022
datayouhave = rand(8, 5); % replace this with your data
t = array2table(datayouhave, "VariableNames", ["Maths", "Physics", "Politics", "Economy", "English"]);
name = ["AAA", "AAA", "AAA", "BBB", "BBB", "BBB", "CCC", "CCC"]';
t = [array2table(name) t];
t
3 Comments
Walter Roberson
on 6 Jul 2022
Which MATLAB version are you using?
Try
datayouhave = rand(8, 5); % replace this with your data
t = array2table(datayouhave, 'VariableNames', {'Maths', 'Physics', 'Politics', 'Economy', 'English'});
name = {'AAA', 'AAA', 'AAA', 'BBB', 'BBB', 'BBB', 'CCC', 'CCC'}.';
t = [array2table(name) t];
t
More Answers (1)
Walter Roberson
on 6 Jul 2022
You cannot create that kind of table in MATLAB.
In order to have a row name span multiple rows, you will need to create a table with three rows and two variables. The first variable will be the Name. For each row, the second variable must be a complete table.
M = round(randn(15, 5), 1)
varnames = ["Maths", "Physics", "Politics", "Economy", "English"];
T1 = array2table(M(1:5,:), 'VariableNames', varnames);
T2 = array2table(M(6:10,:), 'VariableNames', varnames);
T3 = array2table(M(11:15,:), 'VariableNames', varnames);
names = ["Ramu"; "Rihith"; "Swarmy"];
Output = table('Size', [3 2], 'VariableTypes', ["string", "table"], 'VariableNames', ["Name"; "Marks"]);
Output.Name = names;
Output.Marks = {T1; T2; T3};
Output
Output.Marks{1}
So you can construct the table, but it will not display nicely.
0 Comments
See Also
Categories
Find more on Quadratic Programming and Cone Programming 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!