2

以前、行列と文字列を .txt ファイルに含めることについて質問しました。セルを追加する必要があります。私の前の質問から:

str = 'This is the matrix: ';
mat1 = [23 46; 56 67];
fName = 'output.txt';
fid = fopen(fName, 'w');
if fid >= 0
    fprintf(fid, '%s\n', str);
    fclose(fid);
end
dlmwrite(fName, mat1, '-append', 'newline', 'pc', 'delimiter', '\t');

今、私は文字列を追加したい:

'ABC' [10011] [2]
'DEF' [10023] [1] 

関連リンク:

http://www.mathworks.com/help/techdoc/ref/fileformats.htmlhttp://www.mathworks.com/support/solutions/en/data/1-1CCMDO/index.html?solution=1- 1CCMDO

4

2 に答える 2

3

残念ながら、 DLMWRITECSVWRITEなどの関数を使用してデータのセル配列を書き込むことはできません。ただし、必要な出力を取得するには、 FPRINTFを 1 回呼び出すこともできますが、cell 配列の行にあるすべてのエントリの形式を指定する必要があります。前の質問に対する私の回答に基づいて、次の行を追加します。

str = 'The removed identifiers are: ';   %# Your new string
cMat = {'ABC' 10011 2; 'DEF' 10023 1};   %# Your cell array
fid = fopen(fName,'a');                  %# Open the file for appending
fprintf(fid,'%s\r\n',str);               %# Print the string
cMat = cMat.';                          %'# Transpose cMat
fprintf(fid,'%s\t%d\t%d\r\n',cMat{:});   %# Print the cell data
fclose(fid);                             %# Close the file

新しいファイルの内容 (古い例を含む) は次のようになります。

This is the matrix: 
23  46
56  67
The removed identifiers are: 
ABC 10011   2
DEF 10023   1
于 2010-12-30T18:39:54.770 に答える
0

File Exchangeの cellwriteを使用できます。cellwriteの作成者であるFrancis Barnhartによる MATLABによる混合データの書き込みは一見の価値があるかもしれません。

ファイル ハンドルを受け入れるように cellwrite の署名を変更することは、実行可能なタスクです。既存のファイルにデータを追加できるようにします。

于 2010-12-30T18:27:02.157 に答える