2016-12-06 8 views
-3

私は行列 'UserID'にIDのリストを持っています。このUserIDがヘッダ行であるxlsまたはcsvファイルを作成します。行数は2200000、列数は11です。列のラベルは1996年から2006年の年です。私はこのページ読み:特定の行と列のヘッダーを持つxlsファイルまたはcsvファイルを作成する

https://www.mathworks.com/matlabcentral/answers/101309-how-do-i-use-xlswrite-to-add-row-and-column-labels-to-my-matlab-matrix-when-i-write-it-to-excel-in-m

をしかし、このコードは私にエラーを与えます。場合によっては行数が少ないこともありますが、時には答えが出ません。誰かがこれを行うプログラムを導入できますか? (MATLABあるいはC#のコード付き)

私はこのコードを書く:

data=zeros(2200000,11); 
data_cells=num2cell(data); 
col_header={'1996','1997','1998','1999','2000','2001','2002','2003','2004','2005','2006'}; 
row_header(1:2200000,1)=UserID; 
output_matrix=[{' '} col_header; row_header data_cells]; 
xlswrite('My_file.xls',output_matrix); 

をし、私はこのエラーを取得する:あなたがxlswriteを使用する場合

The specified data range is invalid or too large to write to the specified file format. Try writing to an XLSX file and use Excel A1 notation for the range argument, for example, ‘A1:D4’.

+1

ここではコードを記述するのではありません。あなたが試したことを見せて、間違っていることを説明してください。 – RandomStranger

+0

@Basこの投稿を更新しました。 – Eli

答えて

0

あなたは、その行の数に制限されていますあなたのExcel version permits

The maximum size of array A depends on the associated Excel version.

Excel 2013では、最大値は1048576、wh ichはあなたの2200000x11マトリックスより1151424少ない行です。

あなたはもっと自分のデータをエクスポートし、その中の先端にも参照するcsvwriteを使用します。

csvwrite does not accept cell arrays for the input matrix M. To export a cell array that contains only numeric data, use cell2mat to convert the cell array to a numeric matrix before calling csvwrite. To export cell arrays with mixed alphabetic and numeric data... you must use low-level export functions to write your data.

EDIT:あなたのケースでは

、あなたは少なくともこの変化の一部をすべきコード:

col_header = 1996:2006; 
output_matrix=[0, col_header; row_header data]; 

あなたは0を定義する必要はありませんをセル配列として使用します(また、data_dellsは不要です)。ただし、UserIDを数値変数に変換する必要があります。

+0

私はこのコードを書いた: 'data = 0(1000000,11); data_cells = num2cell(data);col_header = {'1996'、 '1997'、 '1998'、 '1999'、 '2000'、 '2001'、 '2002'、 '2003'、 '2004'、 '2005'、 '2006'}; row_header(1:1000000,1)= userId(1:1000000); output_matrix = [{''} col_header; row_header data_cells];csvwrite( 'My_file.csv'、ce​​ll2mat(output_matrix)); 'これは私にエラーが出る:'入力セル配列のすべての内容は同じデータ型でなければならない 'このエラーの理由はわからない!!別の質問:私は2200000行をCSVファイルにすべて保存できますか? – Eli

+0

上記のドキュメントで述べたように、_ "数値データのみを含むセル配列" _をエクスポートすることができます。あなたの 'col_header'と多分' row_header'も文字列で、あなたの行 'output_matrix = [{''} col_header; row_header data_cells] 'セル配列にchar(' ''')を追加し、それを混在させます。 – EBH

関連する問題