Convert Struct to Cell Array With Column Headers

Converts a populated struct into a cell array with field names as column headers
2.2K Downloads
Updated 30 Mar 2006

No License

Accepts a 1-dimensional struct array (in the format 1xn) and converts it into a cell array. The first row of the cell array has the struct's field names in each column; the data from each of those fields for each entry in the struct array appears in subsequent rows. The idea is to make it easy to prep data for writing to an Excel spreadsheet using xlswrite.

Example:
weather =

1x3 struct array with fields:
temp
rainfall

>> wxcell = structToCellArrayWithHeaders ( weather )

wxcell =

'temp' 'rainfall'
[ 68] [ 0.2000]
[ 80] [ 0.4000]
[ 72] [ 0]

Cite As

Andrew Blackburn (2024). Convert Struct to Cell Array With Column Headers (https://www.mathworks.com/matlabcentral/fileexchange/10564-convert-struct-to-cell-array-with-column-headers), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2006a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Data Type Conversion in Help Center and MATLAB Answers

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes
1.0.0.0