Is there a way to get the value of an array to the shape of a variable? Even when I select a single value of an array, say A(1:1, 1:1)
, it still complains when I compile and want to assign this to a variable:
有没有一种方法可以让数组的值变成变量的形状?即使我选择一个数组的单个值,比如a(1:1, 1:1),当我编译时,它仍然会报错,并想把它赋给一个变量:
Error: Incompatible ranks 0 and 1 in assignment at (1)
The goal in the end is something like this:
最终的目标是这样的:
H = MAXVAL(matrix) - epsilon
IF ( matrix(i:i, i:i) >= H ) THEN
... but I cannot make this comparison because H is a variable and matrix(i:i, i:i)
a 1x1 array. Is the only possibility for this to work to make H and array, too?
…但是我不能做这个比较因为H是一个变量和矩阵(I: I, I: I)一个1x1的数组。这是唯一的可能让它也能生成H和数组吗?
Thank you for your help!
谢谢你的帮助!
1 个解决方案
#1
4
Do not specify a range, use a single element:
不要指定范围,使用单个元素:
A(1,1)=1
Your statement would then read:
你的发言将如下:
H = MAXVAL(matrix) - epsilon
IF ( matrix(i, i) >= H ) THEN
Background:
背景:
Fortran allows you to work on sub-arrays like:
Fortran允许你在子数组上工作:
A(1:10,2:5)
which would be a 10x4
array. So A(1:1,1:1)
is in fact an array (1x1) (as you noted). A(1,1)
, on the other hand, is a scalar and can be treated as such.
也就是一个10x4的数组。A(1:1,1:1)实际上是一个数组(1x1)另一方面,A(1,1)是一个标量,可以这样处理。
#1
4
Do not specify a range, use a single element:
不要指定范围,使用单个元素:
A(1,1)=1
Your statement would then read:
你的发言将如下:
H = MAXVAL(matrix) - epsilon
IF ( matrix(i, i) >= H ) THEN
Background:
背景:
Fortran allows you to work on sub-arrays like:
Fortran允许你在子数组上工作:
A(1:10,2:5)
which would be a 10x4
array. So A(1:1,1:1)
is in fact an array (1x1) (as you noted). A(1,1)
, on the other hand, is a scalar and can be treated as such.
也就是一个10x4的数组。A(1:1,1:1)实际上是一个数组(1x1)另一方面,A(1,1)是一个标量,可以这样处理。