Re: Unpacking algoritmn [message #39326] |
Sat, 15 May 2004 16:03  |
Tmorri
Messages: 10 Registered: April 2004
|
Junior Member |
|
|
Thanks for your replay. I made a little mistake in the statement of the
problem, what I really need is this:
x1,x2,x3,x4,x5 are variables that can take any value, even zero, (0).
I just want to get rid othe zeroes shown in vector v0
v0=[0 x1 x2 x3 0 x4 x5 x1 0 x2 x3 x4 0 x5 x1 x2 0 x3 x4 x5]
in the following way:
v1=[0 0 0 0 0]
v2=[x1 x2 x3 x4 x5 x1 x2 x3 x4 x5 x1 x2 x3 x4 x5]
Thanks for your help.
Tmorri
|
|
|
|
Re: Unpacking algoritmn [message #39460 is a reply to message #39326] |
Mon, 17 May 2004 09:04  |
tam
Messages: 48 Registered: February 2000
|
Member |
|
|
Tmorri wrote:
> Thanks for your replay. I made a little mistake in the statement of the
> problem, what I really need is this:
>
> x1,x2,x3,x4,x5 are variables that can take any value, even zero, (0).
>
> I just want to get rid othe zeroes shown in vector v0
>
> v0=[0 x1 x2 x3 0 x4 x5 x1 0 x2 x3 x4 0 x5 x1 x2 0 x3 x4 x5]
>
> in the following way:
>
> v1=[0 0 0 0 0]
>
> v2=[x1 x2 x3 x4 x5 x1 x2 x3 x4 x5 x1 x2 x3 x4 x5]
>
> Thanks for your help.
>
> Tmorri
>
>
Then something like:
v2 = v0[ (lindgen(n_elements(v0)) mod 4) ne 0]
might do the trick. In practice I'd usually split
it out into a couple of lines.
index = lindgen(n_elements(v0))
v2 = v0[ (index mod 4) ne 0]
Regards,
Tom McGlynn
|
|
|
Re: Unpacking algoritmn [message #39461 is a reply to message #39326] |
Mon, 17 May 2004 07:40  |
James Kuyper
Messages: 425 Registered: March 2000
|
Senior Member |
|
|
Tmorri wrote:
> Thanks for your replay. I made a little mistake in the statement of the
> problem, what I really need is this:
>
> x1,x2,x3,x4,x5 are variables that can take any value, even zero, (0).
>
> I just want to get rid othe zeroes shown in vector v0
>
> v0=[0 x1 x2 x3 0 x4 x5 x1 0 x2 x3 x4 0 x5 x1 x2 0 x3 x4 x5]
>
> in the following way:
>
> v1=[0 0 0 0 0]
>
> v2=[x1 x2 x3 x4 x5 x1 x2 x3 x4 x5 x1 x2 x3 x4 x5]
Examples can be useful for illustrating a problem definition, but
they're a poor method for actually defining the problem, as you've
already seen.
The key issue here, is how should the code you're looking for identify
which values to put into v1, and which ones to put into v2? David
Fanning's answer was based upon one assumption, which was compatible
with your first example: that the items to go into v0 are the ones with
a value of 0. Now we know that it's what you want, we have to make a
different guess.
My best guess is that you want to put into v1 every fourth element,
starting with element 0. You want the rest of the elements in v2. Is
that correct? Will the total number of elements always be a multiple of
4, or will there sometimes be a few left over? Will the total number of
elements always be exactly 20?
|
|
|