Path: news.mathworks.com!newsfeed-00.mathworks.com!news.tele.dk!feed118.news.tele.dk!feed116.news.tele.dk!bofh.vszbr.cz!news.radio.cz!newsreader4.netcologne.de!news.netcologne.de!news.mixmin.net!aioe.org!.POSTED!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Data Manipulation (Re-arranging) and Writing to text file
Date: Mon, 18 Jun 2012 15:47:41 -0500
Organization: Aioe.org NNTP Server
Lines: 28
Message-ID: <jro45e$lh6$1@speranza.aioe.org>
References: <jrm6nb$787$1@newscl01ah.mathworks.com> <jrmb7j$5iu$1@speranza.aioe.org> <jrnf37$nlk$1@newscl01ah.mathworks.com> <jrno98$luu$1@speranza.aioe.org>
NNTP-Posting-Host: Umw05Hhhp4pU9Ywjo5rUXQ.user.speranza.aioe.org
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Complaints-To: abuse@aioe.org
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.28) Gecko/20120306 Thunderbird/3.1.20
X-Notice: Filtered by postfilter v. 0.8.2
Xref: news.mathworks.com comp.soft-sys.matlab:771507

On 6/18/2012 12:24 PM, dpb wrote:
...

> x=[1:200]';
> f1=[repmat('%4d',1,6) '\n'];
> f2=[repmat('%4d',1,2) '\n'];
> ix=1;
> while
> ix<length(x)
> fprintf(f1,x(ix:ix+59))
> fprintf(f2,x(ix+60:ix+61))
> ix=ix+66;
> end
...

Just a minor cleanup of a formatting problem and a few fewer magic 
numbers...

i1=1;
while i1<length(x)
   i2=i1+59;
   fprintf(f1,x(i1:i2))
   i1=i2+1; i2=i1+1;
   fprintf(f2,x(i1:i2))
   i1=i2+4;
end

--