Re: XY position of subscripts [message #80171] |
Sun, 13 May 2012 17:09 |
cgguido
Messages: 195 Registered: August 2005
|
Senior Member |
|
|
On Friday, May 11, 2012 12:00:47 PM UTC-5, KH wrote:
> On May 11, 12:56 pm, Gianguido Cianci <gianguido.cia...@gmail.com>
> wrote:
>> Use array_indices
>>
>> print, array_indices(array, where(array eq 1))
>>
>> G
>
> Thank you, this is what I was looking for. I knew it was simple...
> Kim
Welcome. The main advantage of array_indices is that it can think in multi-dimensions and I can't ;-)
|
|
|
Re: XY position of subscripts [message #80178 is a reply to message #80171] |
Fri, 11 May 2012 10:01  |
Mats Löfdahl
Messages: 263 Registered: January 2012
|
Senior Member |
|
|
Den fredagen den 11:e maj 2012 kl. 18:02:40 UTC+2 skrev KH:
> On May 11, 11:36 am, Mats Löfdahl <mats.lofd...@gmail.com> wrote:
>> Den fredagen den 11:e maj 2012 kl. 17:14:27 UTC+2 skrev KH:
>>
>>> Hello,
>>> I have a quick question I was hoping to get some help with.
>>
>>> Assuming you have a 2D array and then use WHERE to find specific
>>> subscripts in the array, how can you convert those subscripts into X
>>> and Y coordinates?
>>
>>> I feel like this is something I should know how to do, but I am
>>> drawing a blank right now.
>>> Thanks,
>>> Kim
>>
>> Here's an example:
>>
>> IDL> Ni=10
>> IDL> Nj=20
>> IDL> A=bytarr(Ni,Nj)
>> IDL> A[4,7]=1
>> IDL> indx=where(A eq 1)
>> IDL> print,A[indx mod Ni, indx / Ni]
>> 1
>
> Thanks for the reply, but what I am looking for are the X and Y
> positions of where the array equals 1. So in your example, how would
> I get X=4 and Y=7 from the subscripts generated by the WHERE command?
Those are the indices I used in the last line: indx mod Ni and indx / Ni.
|
|
|
Re: XY position of subscripts [message #80179 is a reply to message #80178] |
Fri, 11 May 2012 10:00  |
KH
Messages: 9 Registered: August 2011
|
Junior Member |
|
|
On May 11, 12:56 pm, Gianguido Cianci <gianguido.cia...@gmail.com>
wrote:
> Use array_indices
>
> print, array_indices(array, where(array eq 1))
>
> G
Thank you, this is what I was looking for. I knew it was simple...
Kim
|
|
|
|
Re: XY position of subscripts [message #80181 is a reply to message #80180] |
Fri, 11 May 2012 09:02  |
KH
Messages: 9 Registered: August 2011
|
Junior Member |
|
|
On May 11, 11:36 am, Mats Löfdahl <mats.lofd...@gmail.com> wrote:
> Den fredagen den 11:e maj 2012 kl. 17:14:27 UTC+2 skrev KH:
>
>> Hello,
>> I have a quick question I was hoping to get some help with.
>
>> Assuming you have a 2D array and then use WHERE to find specific
>> subscripts in the array, how can you convert those subscripts into X
>> and Y coordinates?
>
>> I feel like this is something I should know how to do, but I am
>> drawing a blank right now.
>> Thanks,
>> Kim
>
> Here's an example:
>
> IDL> Ni=10
> IDL> Nj=20
> IDL> A=bytarr(Ni,Nj)
> IDL> A[4,7]=1
> IDL> indx=where(A eq 1)
> IDL> print,A[indx mod Ni, indx / Ni]
> 1
Thanks for the reply, but what I am looking for are the X and Y
positions of where the array equals 1. So in your example, how would
I get X=4 and Y=7 from the subscripts generated by the WHERE command?
Kim
|
|
|
Re: XY position of subscripts [message #80182 is a reply to message #80181] |
Fri, 11 May 2012 08:36  |
Mats Löfdahl
Messages: 263 Registered: January 2012
|
Senior Member |
|
|
Den fredagen den 11:e maj 2012 kl. 17:14:27 UTC+2 skrev KH:
> Hello,
> I have a quick question I was hoping to get some help with.
>
> Assuming you have a 2D array and then use WHERE to find specific
> subscripts in the array, how can you convert those subscripts into X
> and Y coordinates?
>
> I feel like this is something I should know how to do, but I am
> drawing a blank right now.
> Thanks,
> Kim
Here's an example:
IDL> Ni=10
IDL> Nj=20
IDL> A=bytarr(Ni,Nj)
IDL> A[4,7]=1
IDL> indx=where(A eq 1)
IDL> print,A[indx mod Ni, indx / Ni]
1
|
|
|