GaleofWrath
GaleofWrath

Reputation: 9

how can I get the location for the maximum value in fortran?

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

Answers (2)

High Performance Mark
High Performance Mark

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

francescalus
francescalus

Reputation: 32366

Your question is a little unclear: it could be either of two things you want.

  • One value for the maximum over the entire 250-by-5 subarray;
  • One value for the maximum in each of the 5 250-by-1 subarrays.

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

Related Questions