Path: news.mathworks.com!not-for-mail
From: "Steven Lord" <slord@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: print a matrix ...
Date: Thu, 22 Oct 2009 09:49:43 -0400
Organization: The MathWorks, Inc.
Lines: 32
Message-ID: <hbpnsb$ipv$1@fred.mathworks.com>
References: <hbopub$1m3$1@fred.mathworks.com> <hbp2nj$bmq$1@fred.mathworks.com> <hbpbvr$rrb$1@fred.mathworks.com>
Reply-To: "Steven Lord" <slord@mathworks.com>
NNTP-Posting-Host: lords.dhcp.mathworks.com
X-Trace: fred.mathworks.com 1256219339 19263 172.31.44.65 (22 Oct 2009 13:48:59 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 22 Oct 2009 13:48:59 +0000 (UTC)
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579
Xref: news.mathworks.com comp.soft-sys.matlab:579316



"Venkat " <vpisipati@yahoo.com> wrote in message 
news:hbpbvr$rrb$1@fred.mathworks.com...
> "Branko " <bogunovic@mbss.org> wrote in message 
> <hbp2nj$bmq$1@fred.mathworks.com>...
>> "Venkat " <vpisipati@yahoo.com> wrote in message
>>
>> One possible solution:
>> infid=fopen('filename','wt');
>> fprintf(infid,'%.2f %.2f %.2f\n',A');
>> fclose(infid)
>
> Unfortunately, the dimensions are not fixed, the matrix f X a dimensions, 
> f and a being variables measured from variable input data. Any help will 
> be deeply appreciated.
>
> V

A = rand(3, 4)
fid = fopen('mydatafile.txt', 'wt');
cols = size(A, 2);
formatString = [repmat('%.4f ', 1, cols) '\n'];
fprintf(fid, formatString, A.');
fclose(fid);
edit mydatafile.txt

-- 
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ