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 10:24:25 -0500
Organization: Aioe.org NNTP Server
Lines: 36
Message-ID: <jrnh7c$33j$1@speranza.aioe.org>
References: <jrm6nb$787$1@newscl01ah.mathworks.com> <jrmb7j$5iu$1@speranza.aioe.org> <jrnf37$nlk$1@newscl01ah.mathworks.com>
NNTP-Posting-Host: q9ROquIwoNmofcJt/zdbWg.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:771480

On 6/18/2012 9:48 AM, Stan wrote:
>> x(:,2:end)=[]; % retain column only 1 for simplicity in addressing
> ..
> ..
> ..
>> x=reshape(x,6,length(x)/6)'; % now you've got rows of length 6
>
> Is it possible to extract a subset of a matrix, where you indicate the
> range of matrix elements to be extracted? I mean, after aplying the
> second command (reshaping which gave rows of length 6), could the first
> 11 rows be extracted by specifying (not the row numbers, but) the range
> of matrix elements to be extracted - in this case [1:66]?

Of course, but the linear address of the first 66 isn't the same as the 
first 11 rows as Matlab storage order is column-major.

But, all you need is to write out

x(1:M,:)

for whatever value of M you need and then the one or two or however many 
that aren't full as

x(M+N,1:2)  % for N = 1, 2, ... , whatever it is you want

If there are more remaining of the same pattern then put this in a loop 
and increment by M+N for the first row index.  If the pattern changes, 
then you'll need to add the logic to compute the M and N as you iterate 
through as well, but if you know what it is, then that should be no 
problem even if you have to do it as a lookup table because it's irregular.

NB, of course, that owing to the column major storage order you'll need 
to use the ' (transpose) operator on the submatrices to write them in 
rows as displayed on the screen to the file...

--