0
votes

I have a structure which I want to write to excel file.

For example, I want to write A which is structure to excel. A contains both textdata and numbers which I want to write to excel.

>> A.textdata

ans = 

    Sheet1: {'Coco-Cola'  'CCE'}

>> A.data

ans = 

    Sheet1: [4 46.7100 46.2800 185.1200 -0.0092 -1.7200]

The output should be like this: enter image description here

Need some guidance on how to do it.

What I have tried so far:

1) xlswrite(filename,A);

It gave me this error: Error using xlswrite (line 166) Input data must be a numeric, cell, or logical array.

2) Acell = struct2cell(A);xlswrite(filename,Acell);

It gave me this error:An error occurred on data export in CSV format. Caused by: Undefined function 'real' for input arguments of type 'struct'.

1
I tried that xlswrite(filename,A). It gave me an error:Error using xlswrite (line 166) Input data must be a numeric, cell, or logical array. - lakshmen
A is a struct and expected input of xlswrite is a numeric, cell, or logical array. Merge the data in A to a cell and then xlswrite it. - JunYoung Gwak
@lakesh, a question should be more than "I need some guidance". Have you thought about your problem? What did you come up with? Why didn't it work? Moreover, in your example I can't see how you can expect do generate that Excel sheet just from the information in A – crucial info is missing. Please revise your question. - A. Donda
@A.Donda I have already tried xlswrite(filename,A). It did not work for me.. - lakshmen
@JunYoungGwak I did like you said.I converted the struct to cell using the struct2cell function. Acell = struct2cell(A); xlswrite(filename,Acell); But it gave me this error:An error occurred on data export in CSV format. Caused by: Undefined function 'real' for input arguments of type 'struct'. - lakshmen

1 Answers

1
votes

please try the following:

writetable(struct2table(A), 'parameters.xlsx');

Here, A is a structure