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: Fri, 20 Aug 2010 21:13:20 +0200

On Fri, Aug 20, 2010 at 7:33 PM, Judd Storrs <address@hidden> wrote:
> On Fri, Aug 20, 2010 at 1:03 PM, forkandwait <address@hidden> wrote:
>>
>> Is there a more graceful way to handle this?  I always mess up my index
>> calculations ("starti" and "endi" below) and it pisses me off.  Another
>> constraint is that I would like to avoid 3-d matrices, though maybe they
>> are the
>> best solution
>>
>> (I find that code that uses more than 2-d becomes brittle when
>> other people try to maintain it -- hence the cellarray "x" to store each
>> county.)
>
>
> Well, I don't know a one-liner but, you can at least be rid of the index
> calculations if you become more favorable toward 3D:
> cntyagesex = reshape(data(:,end), 39, 36, []) ;
> for ii = 1:39
>   x(ii) = squeeze(cntyagesex(ii,:,:)) ;
> endfor
> cntyagesex = reshape(cntyagesex, 29*36,[]) ;
> I have also wanted an easy way to slice up a matrix into a cell array (for
> use in parcellfun) but I don't know how to do that.
>

Example?

-- 
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]