How to add header row to cell array?

Hi everyone.
I have a cell array like this:
I would like to add a header row with the following fields: ['Type' 'Latency' 'Description'].
I've tried the reshape function but can't get good results. Can anyone help me please?

답변 (1개)

dpb
dpb 2022년 5월 12일

1 개 추천

A cell array doesn't have the facility for headers, per se; if you add to it you've effectively created more data -- and when you go to use the data, then you have to remove or not reference that row to operate on the data alone. This is a lot of effort.
I'd suggest to use a table instead; you get the header effectively for free from the column/variable names.
tC=cell2table(C,'VariableNames',{'Type','Latency','Description'});

댓글 수: 5

Thanks for the reply.
I need to add the header because then I have to export everything as a .txt file
I solved it with the following commands:
header = {'Type','Latency','Description'};
output=[header; BB];
Stephen23
Stephen23 2022년 5월 12일
Using a table would probably be better data design, judging by your screenshot and requirement to export to TXT.
Thanks, I'll try!
Do you have any suggestions on how to export in .txt?
dpb
dpb 2022년 5월 12일
See writetable It'll do whatever you need...
thanks you !!

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

카테고리

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

질문:

2022년 5월 12일

댓글:

2022년 5월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by