help-octave
[Top][All Lists]
Advanced

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

RE: Help with matrix replication


From: Richardson, Anthony
Subject: RE: Help with matrix replication
Date: Thu, 20 Dec 2012 17:21:27 +0000

> Bård Skaflestad
> Subject: Re: Help with matrix replication
> 
> On Thu, 2012-12-20 at 16:50 +0000, Richardson, Anthony wrote:
> > I want to duplicate the rows in a matrix n times and then duplicate
> > the columns n times.
> 
> Here is one simple way,
> 
>     ix = @(sz, n) cumsum (mod (1 : n*sz, n) == 1);
> 
>     a = [ 1, 2, 3 ; 4, 5, 6 ];
>     n = 2;
> 
>     i = ix (size (a, 1), n);
>     j = ix (size (a, 2), n);
> 
>     b = a (i, j);
> 
> It uses quite a bit of memory, though.
> 
> 
> Sincerely,
> --
> Bård Skaflestad <address@hidden>

This seems to be equivalent to:

b = a((1:rows(a))(ones(1,n),:), (1:columns(a))(ones(1,n),:));

(Your i vector is the same as (1:rows(a))(ones(1,n),:) and your j vector is 
(1:columns(a))(ones(1,n),:).)

Tony

reply via email to

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