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

Learn moreOpportunities for recent engineering grads.

Apply Today**New to MATLAB?**

Asked by James
on 21 Aug 2011

I have a 2x100 structured array

and I want to store and export the values in the 2nd row into Excel. How can I do this?

*No products are associated with this question.*

Answer by Fangjun Jiang
on 21 Aug 2011

%example data a(2,9).field1='text' a(2,9).field2=rand;

%code prop=fieldnames(a); N_prop=length(prop);

mat=cell(N_prop,size(a,2)); for k=1:N_prop [mat{k,:}]=deal(a(2,:).(prop{k})); end

xlswrite('test.xls',mat);

%if the data has only one field called .cdata mat=cell(1,size(a,2)) [mat{1,:}]=deal(a(2,:).cdata); xlswrite('test.xls',mat);

## 10 Comments

## Fangjun Jiang (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/14145#comment_31273

How many fields does each structure have? Do you want to store all the fields or a particular field? Please provide a 2x3 example.

## James (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/14145#comment_31274

<1x1 struct> <1x1 struct> <1x1 struct>

<1x1 struct> <1x1 struct> <1x1 struct>

## Fangjun Jiang (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/14145#comment_31275

No. Assume your variable name is a, what is a(1,1),a(1,2),a(1,3),a(2,1),a(2,2),a(2,3)?

## James (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/14145#comment_31276

yes

## James (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/14145#comment_31277

and i want to store a(2,1) a(2,2) a(2,3) etc

## James (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/14145#comment_31278

a(2,1).cdata is just an integer and I want to export all these

## Fangjun Jiang (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/14145#comment_31279

Does a have only one field called 'cdata'? That is my question.

## James (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/14145#comment_31293

yes just the 1 field sorry

## Fangjun Jiang (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/14145#comment_31300

Please accept some of your questions. I believe they are answered. It's a conclude of the post as well as acknowledging that others did help to solve your problem.

## Oleg Komarov (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/14145#comment_31303

I stopped answering this poster since he never shows:

- any sign of acknowledgment;

- improvement in the formulation of his questions

- understanding of the fact that an accepted answer is a reference/potential answer for other users as well.