How to Merge the cells and name?
12 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1056585/image.jpeg)
1 Commento
Walter Roberson
il 6 Lug 2022
How does this differ from the previous similar questions you have posted on the topic?
Risposta accettata
Chunru
il 6 Lug 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 Commenti
Walter Roberson
il 6 Lug 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
Più risposte (1)
Walter Roberson
il 6 Lug 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 Commenti
Vedere anche
Categorie
Scopri di più su Quadratic Programming and Cone Programming in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!