Path: news.mathworks.com!not-for-mail
From: "stephen " <huangj5@nationwide.com>
Newsgroups: comp.soft-sys.matlab
Subject: Writing formatted text files when column number of the ouput is uncertain?
Date: Tue, 31 Jul 2007 13:34:16 +0000 (UTC)
Organization: Nationwide Mutual Insurance Co.
Lines: 14
Message-ID: <f8ndon$pv1$1@fred.mathworks.com>
Reply-To: "stephen " <huangj5@nationwide.com>
NNTP-Posting-Host: webapp-01-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1185888856 26593 172.30.248.36 (31 Jul 2007 13:34:16 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 31 Jul 2007 13:34:16 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 642723
Xref: news.mathworks.com comp.soft-sys.matlab:421850


I want to export some outputs by writing a formatted text file. For example, if there are three columns in my output, I will code as follows.

fid=fopen(&#8216;test.txt&#8217;,&#8217;w&#8217;)
fprintf=(fid, &#8216;%12.8f, %12.8f, %12.8f\r\n&#8217;, test&#8217;)
fclose(fid)

However, the number of the columns in the output is not certain. For example, the number of output depends on another variable called &#8220;NumOut&#8221;, e.g. NumOut=4, the output has four columns; NumOut=8, the output has eight columns;etc. 

If that&#8217;s the case, how to make the code or the format flexible so that it would automatically adjust the format to accommodate different numbers of column in the output when writing a formatted text file?

Thanks,

Stephen