- 积分
- 2127
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2013-6-12
- 最后登录
- 1970-1-1
|
楼主 |
发表于 2014-8-30 12:11:52
|
显示全部楼层
参考版主的意见, 做了一个测试代码, 如下:
- program main
- implicit none
- integer :: n
- real(4), allocatable, dimension(:,:) :: A
- n=8
- allocate(A(n,n))
- A(1,:)=(/24.,64.,8.0,6.0,2.,6.,12.,26./)
- A(2,:)=(/12.,25.,5.0,2.0,6.,9.,12.,20./)
- A(3,:)=(/42.,86.,82.,74.,120.,45.,42.,80./)
- A(4,:)=(/38.,80.,42.,14.,18.,49.,21.,35./)
- A(5,:)=(/36.,78.,62.,54.,54.,40.,29.,96./)
- A(6,:)=(/96.,70.,52.,34.,38.,65.,12.,46./)
- A(7,:)=(/60.,120.,12.,2.,40.,8.,12.,24./)
- A(8,:)=(/80.,30.,24.,4.0,6.,16.,36.,56./)
- !call matrixOutput(n,A,6)
- print *,"Maxval of A:",maxval(A)
- print *,"Maxloc of A:",maxloc(A)
- print *,"Maxval2 of A:",maxval(A,A<120)
- print *,"Maxloc2 of A:",maxloc(A,A<120)
- end program
复制代码
结果如下:
- Maxval of A: 120.000000
- Maxloc of A: 7 2
- Maxval2 of A: 96.0000000
- Maxloc2 of A: 6 1
复制代码
现在的问题是, 如果数组中有两个相同的极大值, 比如示例代码中有两个120, 我希望取到的第二个极大值是另外一个120
也就是说, 我希望是按位置取掩码, 而不是按值取掩码
请教大侠实现方法, 多谢了
|
|