problem with writting data to excel from matlab

1 回表示 (過去 30 日間)
best16 programmer
best16 programmer 2017 年 5 月 10 日
編集済み: dpb 2017 年 5 月 11 日
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

採用された回答

dpb
dpb 2017 年 5 月 10 日
>> 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 件のコメント
best16 programmer
best16 programmer 2017 年 5 月 11 日
thank you , it works great but when i use columns with different dimensions it don't work.
dpb
dpb 2017 年 5 月 11 日
編集済み: dpb 2017 年 5 月 11 日
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...)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by