[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: what is the proper syntax ?
From: |
Jaroslav Hajek |
Subject: |
Re: what is the proper syntax ? |
Date: |
Mon, 17 Aug 2009 21:22:40 +0200 |
On Mon, Aug 17, 2009 at 6:29 PM, Christoph
Ellenberger<address@hidden> wrote:
> Sorry to bother with something so trivial but I am not finding the proper
> syntax anywhere.
>
> I try to extend a vector [1 2 3] into a matrix
> 1 2 3
> 1 2 3
> 1 2 3
> ...
>
> using any possible combination I think it might be (also the ones I am sure
> they are not)
>
> [1 2 3].* ones(10,1)
> [1 2 3].* ones(10,3)
> [1 2 3].* ones(10,1)'
> [1 2 3].* ones(10,3)'
> [1 2 3]* ones(10,1)
> [1 2 3]* ones(10,3)
> [1 2 3]* ones(10,1)'
> [1 2 3]* ones(10,3)'
> ...
>
> and I always get an error using MinGW 3.2.0. Can someone point me to the
> proper syntax and confirm that it is or is not a bug ?
>
what you want is
ones (10, 1) * [1 2 3]
or use
repmat ([1 2 3], 10, 1)
which is faster for large vectors. In fact the most efficient way is
[1 2 3] (ones (1, 10), :)
which is close to what repmat does intrinsically.
hth
--
RNDr. Jaroslav Hajek
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz