help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Slicing submatrices -- more graceful/ vectorized way?


From: Jaroslav Hajek
Subject: Re: Slicing submatrices -- more graceful/ vectorized way?
Date: Mon, 23 Aug 2010 07:14:08 +0200

On Mon, Aug 23, 2010 at 1:15 AM, forkandwait <address@hidden> wrote:
> Jaroslav Hajek <highegg <at> gmail.com> writes:
>
>> cntyagesex = reshape(data(:,end), 39*36, []);
>> idx = 1:36;
>> for ii = 1:39
>>  idx += 36;
>>  x{ii} = cntyagesex(starti:endi,:);
>> endfor
>
> I think we mean
>
> cntyagesex = reshape(data(:,end), 39*36, []);
> idx = 1:36;
> for ii = 1:39
>  x{ii} = cntyagesex(idx,:);
>  idx += 36;
> endfor
>
> but otherwise, adding 36 to the index matrix is exactly what I was looking 
> for.

Oh yes, sorry.

> It shifts it perfectly to the next section. I put the update at the end of the
> for loop or it misses the first section.
>

You can also use:

x = mat2cell (cntyagesex, 36*ones (1, 39), size (cntyagesex, 2));

hth

-- 
RNDr. Jaroslav Hajek, PhD
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz



reply via email to

[Prev in Thread] Current Thread [Next in Thread]