Re: How can I append a leading or trailing column to an existing array? [message #51347] |
Fri, 17 November 2006 02:08 |
Wox
Messages: 184 Registered: August 2006
|
Senior Member |
|
|
On Fri, 17 Nov 2006 11:06:26 +0100, Wox <nomail@hotmail.com> wrote:
> a = [ [1,1], [1,1] ]
> b = [[2],[2]]
> c=[a,b]
>
>
> So, make sure b is a column vector. Define b that way or use transpose
> or reform.
>
Oeps, didn't see the Benjamin's reply.
|
|
|
Re: How can I append a leading or trailing column to an existing array? [message #51348 is a reply to message #51347] |
Fri, 17 November 2006 02:06  |
Wox
Messages: 184 Registered: August 2006
|
Senior Member |
|
|
On 16 Nov 2006 13:22:19 -0800, willettk@gmail.com wrote:
> My way:
>
> a = [ [1,1], [1,1] ]
> b = [2,2]
> c = intarr[3,2]
> c(0,*) = b
> c(1:2,*) = a
>
> (there must be a better way . . . )
a = [ [1,1], [1,1] ]
b = [[2],[2]]
c=[a,b]
So, make sure b is a column vector. Define b that way or use transpose
or reform.
|
|
|
Re: How can I append a leading or trailing column to an existing array? [message #51352 is a reply to message #51348] |
Thu, 16 November 2006 13:52  |
Benjamin Hornberger
Messages: 258 Registered: March 2004
|
Senior Member |
|
|
willettk@gmail.com wrote:
> G'day,
>
> I'm looking for a quick (ie, one-line method) of appending a column
> vector to an existing array. As a simple example I would like to make:
>
> 1 1
> 1 1
>
> into
>
> 2 1 1
> 2 1 1
>
> I can think of a few ways to do it (one is listed below), but I would
> really like to do it using array concatenation. I've read a good
> tutorial about it at Coyote's website, but can't figure out the proper
> bracketing. Any ideas?
>
IDL> a=[[1,1],[1,1]]
IDL> print,a
1 1
1 1
IDL> b=[[2],[2]]
IDL> print,b
2
2
IDL> c=[b,a]
IDL> print,c
2 1 1
2 1 1
The key is creating b with the correct dimensions. Another option is
IDL> b=reform([2,2],1,2)
IDL> print,b
2
2
Cheers,
Benjamin
|
|
|