- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, could I get the indexes of elements in an array that satisfies the defined condition. For example,
I have an array, A=(/3,6,1,2,7/)
I want to know the positions of elements that is greater than 3, the result should be
(/2,5/)
Thanks very much and I think this is a useful function.
I have an array, A=(/3,6,1,2,7/)
I want to know the positions of elements that is greater than 3, the result should be
(/2,5/)
Thanks very much and I think this is a useful function.
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
integer, allocatable :: ar(:)
allocate ar(size(a))
! Location (subscripts) of elements > 3
ar = maxloc(a, MASK=a>3)
Lookup maxloc and minloc in the help
Les
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Les, I guess no.
I use print *, maxloc(a, MASK=a>3). The result has only one value. I guess this means: find the position of the element that has the maximal value from a set of elements whose values are greater than 3 in the array. So a sub-array whose values are greater than 3 is cut from the oringinal array and then find position.
Or I think I should be wrong.

I use print *, maxloc(a, MASK=a>3). The result has only one value. I guess this means: find the position of the element that has the maximal value from a set of elements whose values are greater than 3 in the array. So a sub-array whose values are greater than 3 is cut from the oringinal array and then find position.
Or I think I should be wrong.


Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page