Re: equivalents for find function in matlab?

From: David Ian Brown <dbrown_at_nyahnyahspammersnyahnyah>
Date: Tue, 13 Feb 2007 12:58:37 -0700

Unfortunately the ind function only works for 1D arrays. To use it you
need first to convert A to a 1D array using ndtooned. Then, after using
ind,
you need to convert it back to a 2D array using onedtond.

Fortunately the most recent version of NCL has a where function
that lets you set values in a array based on where the expression is
True *and* where it is False.

Using where you can do the whole operation in 1 line:

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

  -dave

On Feb 13, 2007, at 12:19 PM, 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

_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Tue Feb 13 2007 - 12:58:37 MST

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