フィルターのクリア

How do I format and write a numeric array to a file as text?

18 ビュー (過去 30 日間)
Brian
Brian 2011 年 7 月 5 日
What's the easies way to write an array to a formatted file. If I have 16 columns, it seems cumbersome that I have to specify the individual format for each column and then print it in a for loop. Isn't there something like this?
Arrayprint(fid,Data,'f10.5')
thanks

回答 (3 件)

Jan
Jan 2011 年 7 月 5 日
DLMWRITE can create such files. But FPRINTF is vectorized also, so you do not need a loop:
x = rand(100, 16);
fmt = [repmat('%10.5f ', 1, 15), '%10.5f\n'];
fid = fopen(FileName, 'w');
fprintf(fid, fmt, x'); % transposed!
fclose(fid);

Brian
Brian 2011 年 7 月 6 日
I don't see where DLMWRITE can determine that I have 16 columns and automatically insert a '\n' but I'll keep looking into it. In the meantime, your approach works great and I'll simply do that. Perhaps using the "size" command along with "repmat" I can come up with something. thanks very much!

Brian
Brian 2011 年 7 月 6 日
I found that DLMWRITE works exactly like I want it to.
dlmwrite(FileName,output,'precision',5,'delimiter',' ')
thanks again for the information. I was unaware of that command.

カテゴリ

Help Center および File ExchangeText Data Preparation についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by