Is it possible to emulate the FORTRAN syntax (%18.3f\t)*N to reuse the format conversion specifier N times with the FPRINTF function in MATLAB 7.3 (R2006b)?

2 ビュー (過去 30 日間)
I have a large MxN matrix X that is tab-delimited. Each column has the same format, and I use FPRINTF with the format specifier %18.3f\t for each element.
I would like to know if there is a way to emulate the FORTRAN syntax (%18.3f\t)xN to reuse the format conversion specifier N times to process an entire row.

採用された回答

MathWorks Support Team
MathWorks Support Team 2010 年 1 月 22 日
The ability to emulate the FORTRAN syntax (%18.3f\t)xN to reuse the format conversion specifier N times with the FPRINTF function is not available in MATLAB 7.3 (R2006b).
While this syntax is available in several programming languages, it cannot be emulated with FPRINTF in MATLAB code. It can be emulated for file input with the TEXTSCAN function, but there is no file output equivalent for TEXTSCAN in MATLAB.
To work around this issue, call the FPRINTF function for each variable or element in a nested FOR loop, as shown below:
for i = 1:nrows
for j = 1:ncols
fprintf(%18.3f\t,...)
end
end
The MATLAB FPRINTF function, in turn, calls your operating system's C language FPRINTF function.
Attempts to use SPRINTF in the above loop to build a long formatting string that can then be passed FPRINTF could lead to be robustness issues concerning buffer sizes. If, at any stage, the formatting string passed to C's FPRINTF exceeds the size of a buffer, any excess will be lost. The sizes of these buffers are machine and platform-dependent. Therefore, assembling long formatting strings in a FOR loop with SPRINTF and passing the whole string to FPRINTF is not recommended.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFortran with MATLAB についてさらに検索

タグ

製品


リリース

R2006b

Community Treasure Hunt

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

Start Hunting!

Translated by