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!

 채택된 답변

the cyclist
the cyclist 2015년 10월 5일

11 개 추천

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

Evan Mitchell
Evan Mitchell 2015년 10월 6일
편집: Stephen23 2015년 10월 6일
That worked perfectly. Thank you for your help!
Garth Mortensen
Garth Mortensen 2018년 11월 24일
+1
bhargav n
bhargav n 2020년 7월 28일
i have been strugling a lot to solve this thank you so much
Wrichik Basu
Wrichik Basu 2021년 3월 13일
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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

태그

질문:

2015년 10월 5일

댓글:

2021년 3월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by