I have a cell structure which has <1*40 struct> inside it. Every structure has the same field names (each having 12 field names and respective values). I want to Export this cell Array into an Excel file such that all the field names become the heading (12 consecutive columns), and below each field Name Comes its respective field values.
I have tried xlswrite by using cell2struct but it does not help.
If anyone could help me with this ?
If your input data looks something like this:
You can process it using a combination of
struct2cell
and simple concatenation.First convert from a cell array to an array of structs:
Then you can get the values using
struct2cell
Then the column names should simply be the
fieldnames
of your structThen you can concatenate the headers with the data to yield the input to
xlswrite
We can condense this a little bit: