help-octave
[Top][All Lists]
Advanced

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

RE: Help with matrix replication


From: Bård Skaflestad
Subject: RE: Help with matrix replication
Date: Thu, 20 Dec 2012 18:36:56 +0100

On Thu, 2012-12-20 at 17:21 +0000, Richardson, Anthony wrote:
> > 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.

> This seems to be equivalent to:
> 
> b = a((1:rows(a))(ones(1,n),:), (1:columns(a))(ones(1,n),:));

You are absolutely right.  Mine is, essentially, the same technique.  I
apologise for not recognising this earlier.  Which, if any, of these you
would employ is up to you.


Sincerely
-- 
Bård Skaflestad <address@hidden>



reply via email to

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