Re: equivalents for find function in matlab?

From: Adam Phillips <asphilli_at_nyahnyahspammersnyahnyah>
Date: Tue, 13 Feb 2007 12:57:03 -0700

Thanks to Mateus for replying...

The script Mateus provided will work for a one dimensional array, but
not a two dimensional array, as ind only operates on a 1D array. Thus:

arr = ndtooned(A)
Ifind = ind(arr.gt.10.0)
arr(Ifind) = 100.
A = (/ onedtond(arr,dimsizes(A)) /)

Also, in the next release of NCL a new function named where has been added:
http://www.ncl.ucar.edu/Document/Functions/Built-in/where.shtml

this would allow the above to be done in one line, as where can operate
on a multi-dimensional array:

A = where(A.gt.10.0,100,A)

Adam

Mateus da Silva Teixeira wrote:
> Hi Wen,
>
> In NCL you do it as follow:
>
> Ifind = ind ( A .gt. 10.0)
> A(Ifind) = 100.0
>
> very easy also!
>
> Mateus
>
> wenlong_at_hpl.umces.edu escreveu:
>> Hi all,
>>
>> I'm starting to learn NCL.
>>
>> Once thing I'd like to do is to set part of an array to a value I
>> want. In matlab is is really eazy:
>>
>> Say A(1:100,1:200) is a 2D float array,
>>
>> I can do the following to set all locations with value >10 to 100.0
>>
>> %----matlab----
>> Ifind=find(A>10.0); %find the indices that statisfy the condition
>> A(Ifind) =100.0; %reset the value to 100.0
>> %--------------
>>
>> Is there a fast way to do this in NCL? I mean, I really don't
>> want to use tedious do loops.
>>
>>
>> Thanks
>>
>> Wen
>>
>>
>>
>> _______________________________________________
>> ncl-talk mailing list
>> ncl-talk_at_ucar.edu
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk_at_ucar.edu
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

-- 
--------------------------------------------------------------
Adam Phillips			             asphilli_at_ucar.edu
National Center for Atmospheric Research   tel: (303) 497-1726
ESSL/CGD/CAS                               fax: (303) 497-1333
P.O. Box 3000				
Boulder, CO 80307-3000	  http://www.cgd.ucar.edu/cas/asphilli
_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Tue Feb 13 2007 - 12:57:03 MST

This archive was generated by hypermail 2.2.0 : Tue Feb 13 2007 - 14:07:37 MST