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 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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.
Respuesta aceptada
MathWorks Support Team
el 22 de En. de 2010
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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Fortran with MATLAB en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!