How can I export the data and the field names from a structure into an Excel file using MATLAB 7.8 (R2009a)?

I currently have data in stored in a MATLAB structure. I would like to export this data into an Excel spreadsheet such that the field names of the structure are arranged in one column and the scalar data are arranged in the corresponding cells in the adjacent column. Additionally, I would like to add a header to these columns.
Is there an example that shows how you can do this?

 Accepted Answer

In general, you can use the function XLSWRITE to export data into an Excel file. The code below shows how you can write the data and the fieldnames of a structure into an Excel file.
x = struct('a', 1, 'b', 2, 'c', 3, 'd', 4, 'e', 5 )
y = struct('a', 10, 'b', 20, 'c', 30, 'd', 40, 'e', 50 )
c = [ {'Header'} {'XValues'} {'Yvalues'} ; fieldnames(x) struct2cell(x) struct2cell(y)]
s = xlswrite('tempdata.xls', c)

More Answers (0)

Products

Release

R2009a

Community Treasure Hunt

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

Start Hunting!