Mathematica在Excel中的位置函数用于矩阵查找值

时间:2013-10-01 21:15:40

标签: excel excel-vba lookup vba

我在Excel中有一个表,其中包含列和行标题以及相应的值。如何在Excel中查找表中的列和行标题名称/索引值?

在Mathematica中,等效函数是Position [listoflist,value]

编辑:


我在VBA中创建了一个简单的函数,但这远非完美

Function MathematicaPosition(lookvalue As Range, TableRange As Range, RowOrColumn As Boolean) As Integer
Dim r As Integer
Dim c As Integer
Dim tempindex As Integer
Dim i As Integer, j As Integer

tempindex = 0
r = TableRange.Rows.Count
c = TableRange.Columns.Count
For i = 1 To r
    For j = 1 To c 
        If lookvalue.Value = TableRange.Cells(i, j).Value Then
            tempindex = IIf(RowOrColumn, i, j)
        End If
    Next j
Next i
MathematicaPosition = tempindex
End Function

3 个答案:

答案 0 :(得分:0)

请参阅此处的双重查找部分:

http://www.cpearson.com/Excel/TablesAndLookups.aspx

答案 1 :(得分:0)

直接从MrExcel

取消

假设数据阵列在A1:D5:

在G2:=COUNTIF(B2:D5,G1)

在G4中:=IF(ROWS($G$4:G4)>$G$2,"",INDEX($A$2:$A$5,INT(SMALL(IF($B$2:$D$5=$G$1,(ROW($B$2:$D$5)-ROW($B$2)+1)*10^5+COLUMN($B$2:$D$5)-COLUMN($B$2)+1),ROWS($G$4:G4))/10^5)))

在H4中:=IF(ROWS($G$4:G4)>$G$2,"",INDEX($B$1:$D$1,MOD(SMALL(IF($B$2:$D$5=$G$1,(ROW($B$2:$D$5)-ROW($B$2)+1)*10^5+COLUMN($B$2:$D$5)-COLUMN($B$2)+1),ROWS($G$4:G4)),10^5)))

后两个用 Ctrl + Shift + Enter 输入并向下复制。

我不知道Mathematica并且不理解reverse values(基本上是否乘以-1或切换列)。

答案 2 :(得分:0)

Function MathematicaPosition(lookvalue As Range, TableRange As Range, RowOrColumn As Boolean) As Integer
Dim r As Integer
Dim c As Integer
Dim tempindex As Integer
Dim i As Integer, j As Integer

tempindex = 0
r = TableRange.Rows.Count
c = TableRange.Columns.Count
For i = 1 To r
    For j = 1 To c 
        If lookvalue.Value = TableRange.Cells(i, j).Value Then
            tempindex = IIf(RowOrColumn, i, j)
        End If
    Next j
Next i
MathematicaPosition = tempindex
End Function