How can I write to a txt file dynamically?
古いコメントを表示
I want to save this form to a text file:
Col1 Col2 Col3 ..... ColN % Text File Heading
4 45 345 ..... 34
34 88 455 ..... 73
Note: The number of columns "N" is variable.
I need an expression that is a function in "N" inside a loop (1:N)
2 件のコメント
nanren888
2012 年 8 月 1 日
Can you ask the question again in different words?
Ahmed Elkady
2012 年 8 月 1 日
採用された回答
その他の回答 (1 件)
Oleg Komarov
2012 年 8 月 1 日
編集済み: Walter Roberson
2012 年 8 月 1 日
A = [ 4 45 345 34
34 88 455 73];
% Number of columns
N = 2;
% Create/open file discarding content
fid = fopen('test.txt','w');
% Write header
fmt = sprintf('Col%d\t',1:N);
fprintf(fid,[fmt(1:end-1) '\r\n']);
% Write data
fmt = repmat('%.f\t',1,N);
fprintf(fid, [fmt(1:end-2) '\r\n'],A');
fclose(fid);
カテゴリ
ヘルプ センター および File Exchange で Text Data Preparation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!