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

Home » Public Forums » archive » Re: newbie question on array manipulation
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: newbie question on array manipulation [message #66287 is a reply to message #66285] Tue, 05 May 2009 06:06 Go to previous messageGo to previous message
Jean H. is currently offline  Jean H.
Messages: 472
Registered: July 2006
Senior Member
ben.bighair wrote:
> On May 5, 7:40 am, jpardila <blu...@gmail.com> wrote:
>> What is the best way to manipulate one array and remap its values
>> according to conditions?
>> Let's say I have a 2-d array, for all the elements equal to 5 I want
>> to change their values to 0. For values equal to 10 I want to convert
>> to 1 and so on. I am really confused and don't know if to use IF,
>> where, for or while. Thanks for answering this basic one.
>> JP
>
> Hi,
>
> The simplest is to use where - don't forget to use the output COUNT
> argument shown here as "na".
>
> a = WHERE(array EQ 10, na)
> if (na GT 0) then array[a] = 1


Also, if you have several values to changes, you can create a new array.
For example, if you want to change 5 -> 0 and 0 -> 10, but you don't
want to change the old 5 to 10!

copy = array ;copy the array
a = WHERE(array EQ 10, na)
if (na GT 0) then copy[a] = 1

Jean
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: newbie question on array manipulation
Next Topic: Trying to run ENVI_FX_DOIT example

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

Current Time: Thu Oct 09 14:08:44 PDT 2025

Total time taken to generate the page: 1.84123 seconds