How to Merge the cells and name?
17 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaire
Walter Roberson
le 6 Juil 2022
How does this differ from the previous similar questions you have posted on the topic?
Réponse acceptée
Chunru
le 6 Juil 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 commentaires
Walter Roberson
le 6 Juil 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
Plus de réponses (1)
Walter Roberson
le 6 Juil 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 commentaires
Voir également
Catégories
En savoir plus sur Quadratic Programming and Cone Programming dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!