3.5

3.5 | 2 ratings Rate this file 92 downloads (last 30 days) File Size: 1.58 KB File ID: #18830

FAPPENDL

by Mukhtar Ullah

 

19 Feb 2008 (Updated 19 Feb 2008)

No BSD License  

FAPPENDL Write line to file in an intuitive syntax rather than FPRINTF

Download Now | Watch this File

File Information
Description

FAPPENDL(FID, ARG1, ARG2, ...) is the same as
 FPRINTF(FID, '%s\n', [ARG1, ' ', ARG2, ' ', ...]) and hence provides an
 intuitive syntax for writing lines to a file. When all you need is write
 a single line to a file, the original syntax provided by FPRINTF becomes
 quite cumbersome. The best way is illustrate by an example.

 First write a file 'fname1.tex' using FPRINTF:

    pgffile = 'drawing.pgf';
    fid = fopen('fname1.tex', 'w');
    fprintf(fid, '%s\n', '\documentclass{article}');
    fprintf(fid, '%s\n', '\usepackage{pgf}');
    fprintf(fid, '%s\n', '\begin{document}');
    fprintf(fid, '%s\n', ['\input{', pgffile, '}']);
    fprintf(fid, '%s\n', 'Sample text');
    fprintf(fid, '%s\n', 'Sample math $\langle X(t)\rangle$');
    fprintf(fid, '%s\n', '\end{document}');
    fclose(fid);

 Then write another file 'fname2.tex' with the same content but using
 FAPPENDL:

    fid = fopen('fname2.tex', 'w');
    fappendl fid \documentclass{article}
    fappendl fid \usepackage{pgf}
    fappendl fid \begin{document}
    fappendl(fid, ['\input{', pgffile, '}'])
    fappendl fid Sample text
    fappendl fid Sample math $\langle X(t)\rangle$
    fappendl fid \end{document}
    fclose(fid);

MATLAB release MATLAB 7.5 (R2007b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (4)
20 Feb 2008 John D'Errico

This is a very simple utility, but it is moderately simpler than the alternative of fprintf when you wish to create a text file.

Note that it ONLY writes text lines. So if you wanted to write out the value of some numeric variable, you will need to use fprintf anyway, or convert your numbers to a string on your own.

The help is mainly an example of use, but it seems to get the point across.

21 Feb 2008 John D'Errico

By the way, why did I rate this submission as only a 4? After all, it seems to work reasonably nicely.

I did so because I had to figure out that it does not work if I wanted to append a line with numeric data, that I had first to convert the numeric data to a string. While this is not incredibly hard to do, I had to figure that out by testing the code. There is no statement in the help that this will not work. Since the help is really only an example of use, it gives you only a hint of what DOES work. You need to infer the rest.

Excellent help would have told me all I needed to know about how to use it, without ever testing the code.

21 Feb 2008 Mukhtar Ullah

John,
Thank you for your comments. I will change the help accordingly. The idea is not to replace fprintf but to make life easier for simpler tasks.

22 Feb 2008 K L

I stick with saveascii.m

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
fprintf file text write line Mukhtar Ullah 22 Oct 2008 09:49:34
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com