Reputation: 9
I have a 250*2001 matrix. I want to find the location for the maximum value for a(:,i)
where i
takes 5 different values: i = i + 256
a(:,256)
a(:,512)
a(:,768)
a(:,1024)
a(:,1280)
I tried using MAXLOC, but since I'm new to fortran, I couldn't get it right.
Upvotes: 1
Views: 4437
Reputation: 78316
Try this
maxloc(a(:,256:1280:256))
but be warned, this call will return a value in the range 1..5
for the second dimension. The call will return the index of the maxloc
in the 2001*5
array section that you pass to it. So to get the column index of the location in the original array you'll have to do some multiplication. And note that since the argument in the call to maxloc
is a rank-2 array section the call will return a 2-element vector.
Upvotes: 2
Reputation: 32366
Your question is a little unclear: it could be either of two things you want.
Your comments suggest you want the latter, and there is already an answer for the former.
So, in case it is the latter:
b(1:5) = MAXLOC(a(:,256:1280:256), DIM=1)
Upvotes: 1