problem with writting data to excel from matlab

1 vue (au cours des 30 derniers jours)
best16 programmer
best16 programmer le 10 Mai 2017
Modifié(e) : dpb le 11 Mai 2017
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

Réponse acceptée

dpb
dpb le 10 Mai 2017
>> 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]
>>
  2 commentaires
best16 programmer
best16 programmer le 11 Mai 2017
thank you , it works great but when i use columns with different dimensions it don't work.
dpb
dpb le 11 Mai 2017
Modifié(e) : dpb le 11 Mai 2017
It'll work as long as the columns you're concatenating are consistent in the direction of the catenation. Everything's got to be regular from which to build a rectangular 2D cell array. If you must augment some dimension with empty cells to make that occur, so be it; either that or write multiple sections independently (which requires keeping track of where to put them and all that...)

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by