MATLAB Answers


export to excel

Asked by James
on 4 Aug 2011
Latest activity Commented on by Darina
on 17 Feb 2014


I have several variables which are 2x20 structures.

I want to capture and store all the values in the 2nd row and put this into excel.

How can I do this?



No products are associated with this question.

3 Answers

Answer by Fangjun Jiang
on 4 Aug 2011

You may need to use struct2cell() to convert your structure to cell array and then use xlswrite(). Please give an example of your structure. There might be special things to deal with.


Answer by James
on 4 Aug 2011

Okay. I hope this helps. I dont know how else to describe it. For example:

For my 2x20 structured variable called 'variable1'. When I open this in the variable editor, it shows 1x1 structures in every cell.

When double clicking on a cell in the first row this shows: field: cdata value: double

When double clicking on a cell in the second row this shows: field: cdata value: 50 (or some integer number)


Answer by Fangjun Jiang
on 4 Aug 2011

Okay, sounds like not a difficult data structure. Take a look at the example I made up, if similar, you can go ahead. This way, the data written to the Excel file keeps the shape of your structure,i.e. 2 rows 20 columns in your case.



on 4 Aug 2011

how does this work - as it does not point to the original variable "variable1"

I am saying, you can open NewVariable1 in the variable editor, if it looks similar to what you saw on variable1 (except the size), then you can use my code to write to Excel file. Of course, you need to replace "NewVariable1" with "variable1" in the code. I was careful not to over-write the value of your "variable1".

on 17 Feb 2014

I have similar problem but it seems that my nested strucutre is also quite difficult to import to excel. I would like to import all the data from the last field 'flowArray' (which is of type double) into excel sheet?

My nested stucture looks like this:


Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!