How to add headers to a data matrix

54 visualizaciones (últimos 30 días)
Evan Mitchell
Evan Mitchell el 5 de Oct. de 2015
Comentada: Wrichik Basu el 13 de Mzo. de 2021
Hi,
I have a question on how I can add headers to a data matrix. What I've done is created a 5x3 data matrix that I'm wanting to be able to go back and add headers to. I'm new to Matlab so I'm not sure if I need to use the fprint() function or if I need to change from CSV to another format to make this easier. My ultimate goal is to have a data matrix with headers that can be saved as a csv and then exported. Any help would be greatly appreciated!

Respuesta aceptada

the cyclist
the cyclist el 5 de Oct. de 2015
Cell arrays are often the best way to store a combination of text and numeric:
data = rand(4,3);
header = {'Col 1','Col 2','Col 3'};
output = [header; num2cell(data)]
  4 comentarios
bhargav n
bhargav n el 28 de Jul. de 2020
i have been strugling a lot to solve this thank you so much
Wrichik Basu
Wrichik Basu el 13 de Mzo. de 2021
This answer is perfectly fine, but instead of a cell array, a table looks more beautiful. See this answer: https://in.mathworks.com/matlabcentral/answers/178483-how-do-you-add-a-header-to-a-matrix#answer_168011

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by