tprintf

版本 1.01 (10.3 KB) 作者: per isakson
tprintf writes tabular data to a text file
91.0 次下载
更新时间 2017/9/13

查看许可证

tprintf provides an intuitive interface to fprintf for writing tabular data to a text
file. tprintf(filespec,format,A1,...,An) creates a tabular text file by writing the
columns of A1,...,An to columns in the text file.
.
fprintf(fid,format,v1,v2,...), where v1,v2,... are scalars, writes one row. To
print several rows one may put the function in a for-loop. That code is easy to read and
understand. However, with large files speed becomes a problem. fprintf(...,C{:}),
where C is a cell array containing numeric and character data, writes the text file much
faster. With pure numerical data fprintf(...,M), where M is matrix writes even faster.
However, the cell array, C, and the matrix, M, come at a price. It takes some effort to
create them and the resulting code is not all that easy to read and understand - IMO.
With tprintf I try to combined the best of the two.
.
Installation: This submission consists of three m-files and this documentation. Copy the
m-files to a folder on the Matlab search path. Verify that tprintf is working by running
.
>> tprintf( 1, '%d, %4.1f, %s, %s\n', [1;2], rand(2,1),{'first';'second'},['ABC';'DEF'] )
1, 0.6, first, ABC
2, 0.1, second, DEF
ans =
41

引用格式

per isakson (2024). tprintf (https://www.mathworks.com/matlabcentral/fileexchange/64390-tprintf), MATLAB Central File Exchange. 检索来源 .

MATLAB 版本兼容性
创建方式 R2016a
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Text Files 的更多信息

Community Treasure Hunt

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

Start Hunting!
版本 已发布 发行说明
1.01

fixed typo
lines added to "Overwiew"

1.0.0.0