- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
seems to work ...still needs more testing but it compiles. ...(1) didn't. Seems odd that maxval works with the same syntax. Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
![](/skins/images/D3C0B914909A6564BBB97F4AD1ED1973/responsive_peak/images/icon_anonymous_message.png)
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page