comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: array problems
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: array problems [message #61294 is a reply to message #61293] Fri, 11 July 2008 12:02 Go to previous messageGo to previous message
Jean H. is currently offline  Jean H.
Messages: 472
Registered: July 2006
Senior Member
David Sheerin wrote:
> Hi All
> I have a palindromic vector of floats, e.g. [a,b,c,b,a] , and I would like
> to expand it to include the mean between each value like [(0+a)/2, a,
> (a+b)/2, b, (b+c)/2, c, (c+b)/2, b, (b+a)/2, a, (a+0)/2]. Is there any
> elegant way of doing this without having to resort to clunky for loops?
>
> I also would like to repeat this action on the resulting vector.
>
> Thanks for any tips
>
> David
>
>

Hi,
1) get your "average".
nbEntries = n_elements(data)
avg = (data + shift(data,-1)) /2.0
2)add the 1st entry and correct the last entry:
avg = [data[0] / 2.0,avg]
avg[nbEntries] = data[nbEntries-1] / 2.0
3)create the new array by coping each original array, with a "step" of 2
cells betweens two values from the same original array
newData = fltarr(nbEntries*2+1)
nnewData[1:nbEntries*2:2] = data
newData[0:nbEntries*2:2] = avg

Jean
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Where O Where Di My Pointer Go?
Next Topic: Re: Where O Where Di My Pointer Go?

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Sun Oct 12 10:07:38 PDT 2025

Total time taken to generate the page: 0.00194 seconds