Sub heading in matlab table
34 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Davindra Usov
el 16 de En. de 2023
Comentada: Davindra Usov
el 17 de En. de 2023
Hello,
I am trying to create the table shown in the image attached. So far my code generates the table with all the headings but without the 'old fruit' and 'new fruit' headings. How do I add these headings into my code?
table.Properties.VariableNames(1:4) = {'apples','oranges','strawberries','grapefruit'}
writetable(table,'fruit.csv')
thank you
0 comentarios
Respuesta aceptada
Adam Danz
el 16 de En. de 2023
Editada: Adam Danz
el 16 de En. de 2023
There isn't an option to arrange subheadings as described in your attached image.
However, there are several ways to rearrange the table to contain subheadings.
Option 1: nested subheaders
MATLAB R2018b or later
apples = table([3;4],[1;4],'VariableNames',{'old','new'});
oranges = table([3;4],[1;4],'VariableNames',{'old','new'});
strawberries = table([3;4],[1;4],'VariableNames',{'old','new'});
grapefruit = table([3;4],[1;4],'VariableNames',{'old','new'});
fruit = table(apples, oranges, strawberries, grapefruit)
Option 2: nested subheaders version 2
MATLAB R2018b or later
old = table([3;4],[6;4],[5;3],[1;2], 'VariableNames', {'apples','ornages','strawberries', 'grapefruit'});
new = table([1;4],[1;13],[2;11],[3;3], 'VariableNames', {'apples','ornages','strawberries', 'grapefruit'});
fruit = table(old,new)
Option 3: Store subheaders in a table variable
MATLAB R2013b or later
Note that the use of subheadings above makes indexing difficult. Here's a recommendation that preserves the labels but allows for easier indexing:
fruit = table(["old";"old";"new";"new"], ...
[3;4;1;4],[6;4;1;13],[5;3;2;11],[1;2;3;3], ...
'VariableNames', {'age','apples','oranges','strawberries','grapefruit'})
Más respuestas (0)
Ver también
Categorías
Más información sobre Image Processing Toolbox en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!