Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: writing to a .txt file question?
Date: Tue, 10 Jun 2008 04:21:17 +0000 (UTC)
Organization: Inst of Thermomechanics AS CR
Lines: 37
Message-ID: <g2kvft$lnc$1@fred.mathworks.com>
References: <g2k9td$83t$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1213071677 22252 172.30.248.37 (10 Jun 2008 04:21:17 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 10 Jun 2008 04:21:17 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 79193
Xref: news.mathworks.com comp.soft-sys.matlab:472975



"Hydroman S" <amirgsalem@gmail.com> wrote in message
<g2k9td$83t$1@fred.mathworks.com>...
> If I have a matrix 
> 
> a=magic(4)
> 
>     16     2     3    13
>      5    11    10     8
>      9     7     6    12
>      4    14    15     1
> 
> Is it possible to write the matrix data to a *.txt file 
> such that it would look like this:
> 
>     60
>     16     2     3    13
>      5    11    10     8
>      9     7     6    12
>      4    14    15     1
>      carret return
> 
> basically, I need to add the number 60 on top of column 1, 
> and a "carret return" after column 1?  
> 

Hi
Your note on 'column 1' is not very clear, nevertheless, if
the result should look like you presented, the code can be

fid = fopen('test.txt','w');
fprintf(fid,'%2d\n',60);
fprintf(fid,'%3d %3d %3d %3d \n', a');
fprintf(fid,'%s',char(13));
fclose(fid);

Mira