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!