Append character array to first row of a matrix
이전 댓글 표시
Hi there!
I've the following struct array
Astruct =
struct with fields:
data1: [10×5 double]
data2: [10×5 double]
I would like to append a column header to the values stored in the above-metnioned struct before writing to an excel sheet.
data1_header = [1,3,2,4,5];
data2_header = [1,2,3,4,10];
Astruct =
struct with fields:
data1: [10×5 double] % header 'col' + data1_header : ['col1','col3','col2','col4','col5'];
data2: [10×5 double] % ['col1','col2','col3','col4','col10']
Any suggestions on how to do the above will be of great help
댓글 수: 4
Numeric matrices do not have headers like that.
You could use a table, which do have headers:
E.g. use array2table and provide those header names as a string array, then writetable.
Or you could convert the numeric data to a cell array and append the header, but that is a bit... ugly.
If the only purpose of that header is to write it to an extrernal file, then you could just call two functions:
- writecell for the header. and then
- writematrix for the numeric data.
You would need to supply appropriate cell addresses, etc.
Deepa Maheshvare
2020년 5월 20일
편집: Deepa Maheshvare
2020년 5월 20일
Deepa Maheshvare
2020년 5월 20일
Walter Roberson
2020년 5월 20일
Writemode is new as of R2020a.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!