MATLAB: Problem with writting data to excel from matlab

excel exporting data xlswriteMATLAB

i have a problem with xlswrite function when the data is being writting in excel file i get the following error:
#N/A
here' the code that i'm using
d = {'A', 'B','C','D'; A, B, C, D}
xlswrite('my.xlsx',d);
with A,B,C and D are columns with different data
thank you

Best Answer

>> help xlswrite
...
A — Data to write
matrix | cell array
Data to write, specified as a two-dimensional numeric or character array,
or, if each cell contains a single element, a cell array.
If A is a cell array containing something other than a scalar numeric or a
string, then xlswrite silently leaves the corresponding cell in the spreadsheet empty.
...
d = {'A', 'B','C','D'};
xlswrite('my.xlsx',[d;num2cell([A, B, C, D]]);
will work, however.
You can arrange the construction of the end cell array however is convenient; I just used the variables as you had them defined to illustrate what you need to satisfy xlswrite requirements.
Demo:
>> a=randn(5,2); % dummy data set
>> d = {'A', 'B'}; % column headers
>> c=[d;num2cell(a)] % what looks like in cell array
c =
'A' 'B'
[-1.7502] [-0.5336]
[-0.2857] [-2.0026]
[-0.8314] [ 0.9642]
[-0.9792] [ 0.5201]
[-1.1564] [-0.0200]
>> xlswrite('best15.xls',c) % write it out
>> [~,~,r]=xlsread('best15.xls') % read it back to be sure -- raw data
r =
'A' 'B'
[-1.7502] [-0.5336]
[-0.2857] [-2.0026]
[-0.8314] [ 0.9642]
[-0.9792] [ 0.5201]
[-1.1564] [-0.0200]
>>