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

Home » Public Forums » archive » set all elements in 2d array between some range to 1
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: set all elements in 2d array between some range to 1 [message #91009 is a reply to message #91008] Fri, 22 May 2015 16:25 Go to previous messageGo to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Brian Cherinka writes:

>
> My attempted solution was at the bottom. I love value_locate, and I've started tackling this with that but I got stuck. My problem seems a bit more complicated than the uses described on your page.
>
> waved = wave[*]
> uniwave = sort(waved)
> minskywave = skywave - 3
> maxskywave = skywave + 3
>
> v1 = value_locate(minskywave, waved)
> v2 = value_locate(maxskywave, waved)
>
> This gives me the positions in minskywave and maxskywave where the elements in waved lie, but it's not the final answer. I can't combine my "values" array into one big array, because my skywave ranges overlap, and that will give me incorrect binning.
>
> For each element in skywave, I need to find where waved is between skywave+-3, and set those indices to 1. The rest should be set to 0.
>
> Any ideas on how to finish this? Or a simpler way than what I'm attempting. Thanks.

Here is how I would do this for one value in skywave:

skywave = Randomu(-3L, 20)*20-10
skywaveValue= skywave[1]
cuts = [skywaveValue-3., skywaveValue+3]
sortedIndices = Sort(skywave)
sortedData = skywave[sortedIndices]
indices = Value_Locate(cuts, sortedData)
h = cgHistogram(indices, MIN=-1, REVERSE_INDICES=ri)
oneIndices = cgReverseIndices(ri, 1)
ones = skywave*0
solnIndices = (sortedIndices)[oneIndices]
ones[solnIndices] = 1
Print, ""
Print, 'Original Data:'
Print, skywave
Print, ""
Print, 'Find data between ', String(cuts[0], Format='(F0.2)'), $
' and ', String(cuts[1], Format='(F0.2)')
Print, ""
Print, 'Data Between Endpoints: '
Print, skywave[solnIndices]
Print, ""
Print, 'Array of 0s and 1s'
Print, ones
END


Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Function graphics and IDL widgets
Next Topic: Identify whether value is integer in IF statement

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

Current Time: Sat Oct 11 14:12:25 PDT 2025

Total time taken to generate the page: 1.43861 seconds