views:

25

answers:

1

I have a lot of matrix variables. Some have more than 200 rows. How can I export them to an XLS or DAT file with their names? I tried the following:

d = {'X', 'Y'; X Y};
xlswrite('tempdata1.xls', d, 'Sheet1', 'A1');

What I got in the XLS file was only the strings 'X' and 'Y' but without the values of X and Y. X and Y should be vectors (7x1).

+2  A: 

Assuming X and Y are column vectors, try this:

xlswrite('tempdata1.xls', {'X' 'Y'}, 'Sheet1', 'A1');  %# Write the names
xlswrite('tempdata1.xls', [X Y], 'Sheet1', 'A2');      %# Write the data

The reason your cell array d didn't work is because XLSWRITE requires all the cells in the cell array to have just one value in them. In your case, X and Y were vectors, not scalar numerical values or strings, as is the case in this documentation example.

gnovice
Nice. Tnx a lot!!!
Z77