Write out a cell whith characters and numbers to excel

4 次查看(过去 30 天)
Hi,
I create a 1 x 4 cell where:
col 1 = 23 x 20 char (i.e. dates and times)
col 2 = 23 x 1 double (data)
col 3 = 23 x 1 double (data)
col 4 = 23 x 1 double (data)
When I try to write this out to an excel file, I get the error message: Error using xlswrite (line 219) ActiveX - Element of a cell array cannot be a character matrix.
Even if I create a 1 x 4 cell where all 4 columns are type 'char' (I used num2str on the data), I receive the same message when I try to write out the cell to excel.
IdxAbsTilt = AbsTilt>50;
DateBad=datestr(Date(IdxAbsTilt));
BadDataCell{1,1} = DateBad;
BadDataCell{1,2} = num2str(Spd(IdxAbsTilt));
BadDataCell{1,3} = num2str(Dir(IdxAbsTilt));
BadDataCell{1,4} = num2str(AbsTilt(IdxAbsTilt));
xlswrite('BadData.xlsx',BadDataCell) % this does not work;
How do I write out my cell to excel?

采纳的回答

Guillaume
Guillaume 2016-1-20
编辑:Guillaume 2016-1-20
xlswrite only works with cell arrays that contain scalar numeric or string vectors. My guess is that you want end up with 23 rows in your excel spreadsheet. For that, you need to generate a 23x4 cell array:
GoodDataCell = [cellstr(datestr(Date(IdxAbsTilt))), ...
num2cell(Spd(IdxAbsTilt)), ...
num2cell(Dir(IdxAbsTilt)), ...
num2cell(AbsTilt(IdxAbsTilt))];
should do it

更多回答(1 个)

Chetan Rawal
Chetan Rawal 2016-1-22
For more Excel-MATLAB help, checkout this page:

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by