Path: news.mathworks.com!newsfeed.mathworks.com!fu-berlin.de!uni-berlin.de!not-for-mail
From: Herbert Ramoser <herbert_DOT_ramoser@gmx.net>
Newsgroups: comp.soft-sys.matlab
Subject: Re: writing to a text file
Date: Thu, 07 Oct 2004 08:12:05 +0200
Lines: 34
Message-ID: <2sk518F1m7da1U1@uni-berlin.de>
References: <eeec35e.-1@webx.raydaftYaTP>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de 3uyC9M/nya9lqXN//8fwHwE2zfD9paAFlVfuT9BGK3qI9omDoW
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.6) Gecko/20040113
X-Accept-Language: en-us, en
In-Reply-To: <eeec35e.-1@webx.raydaftYaTP>
Xref: news.mathworks.com comp.soft-sys.matlab:233625



Alan Wilkes wrote:
> Hi,
> I'm faced with a queer problem..
> 
> test is a m X 2 matrix that contains something like this :
> 
> 511 0
> 389 375
> 389 379
> 385 362
> ....
> 
> fid = fopen('test.txt','w');
> fprintf(fid,'%d %d\n',test);
> fclose(fid);
> 
> But, when I write it to a file, and read it as "type test.txt" as
> above.. the matrix is messed up as,
> 511 389
> 389 385 ( these r the first column elements in the matrix "test" )
> .....
> 
> It's puzzling why it displays column-major-wise, plus it drops the
> zero (0) in row 1 & Can somebody give me the solution to this weird
> problem.. ?

I notice two things in your code:
- open the file in text mode
   fid = fopen('test.txt','wt');
- The data is taken columnwise so this should give you the desired
   output (in Matlab the data is read columnwise):
   fprintf(fid,'%d %d\n', test.');

-Herbert