Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
1 View

maxloc

Hi,

If I print maxloc(datinlns(n,:,3)), I get the integer location of the maximum value of the second dimension.  n has an assigned value in the code.  If I write imax= maxloc(datinlns(n,:,3)), the compiler complains that there is an " error #6366: The shapes of the array expressions do not conform."

If I write  maxval(datinlns(n,:,3)), I get the expected result: the maximum value of the second dimension.  What is up  with maxloc?  I'm using the 2017 beta.

thanks

0 Kudos
6 Replies
Highlighted
Black Belt
1 View

The result is an array of

The result is an array of type integer.

So you can't assign an array to an integer variable.

[edited ... I thought this would work, but it doesn't]

imax = maxloc(datainlns(n,:,3))(1)

What I have used in the past is this method:

imax = sum(maxloc(datainlns(n,:,3)))

Alternatively, you could define imax as an array of size (1), but then you may need to replace references to imax with imax(1) where scalars are needed.

Regards,

David

0 Kudos
Highlighted
Beginner
1 View

seems to work ...still needs

seems to work ...still needs more testing but it compiles.  ...(1) didn't.  Seems odd that maxval works with the same syntax.  Thanks.

0 Kudos
Highlighted
Black Belt
1 View

The dim argument for maxloc

The dim argument for maxloc and minloc was added in f95. I see very little attempt to restrict usage to f90 in the last decade.

By the way, 16.0.3 seems to treat noold_maxminloc the way 16.0.1 did, no simd.

0 Kudos
Highlighted
1 View

I suggest that both of you

I suggest that both of you take another look at the documentation. What is wanted here is the optional DIM argument. By default, MAXLOC indeed returns an array of results, one for each dimension, giving you the subscript of the maximum value location. In the case of a dimension-1 array argument, specifying DIM=1 will get you the first value from that array which is what you want. Like this:

 imax= maxloc(datinlns(n,:,3),DIM=1)

It gets a bit more complicated if the first argument is an array with more than one dimension, but the standard specifies the behavior.

Retired 12/31/2016
0 Kudos
Highlighted
Beginner
1 View

Hi Steve,

Hi Steve,

I read the documentation and Metcalf w/o much help.  Your solution seems to work.  Since the syntax is the same as that of Maxval (i.e., work on the dimension denoted by the ':', I still don't understand why one needs the DIM=1.  Just an inconsistency in definitions or am I missing something subtle?  Where do you think I can find the best description for the (X,:,Y) syntax?

thanks

0 Kudos
Highlighted
1 View

The definitions of MAXVAL and

The definitions of MAXVAL and MAXLOC, with a single array argument, are different. MAXVAL(array) returns a single value whereas MAXLOC returns an array of indexes telling you WHERE in the array that maximum value is. 

(X,:,Y) is an array section where the second dimension is all the indexes in that dimension so the result is a rank-1 array. (I am assuming X and Y are scalars.) You can look up "array section" in the documentation.

Retired 12/31/2016
0 Kudos