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

Mathematica在Excel中的位置函数用于按值查找矩阵,excel,lookup,vba,Excel,Lookup,Vba,我有一个Excel表格,其中有列标题、行标题和相应的值。如何在Excel中查找表中的列标题和行标题名称/按值索引 在Mathematica中,等价函数是位置[listoflist,value] 编辑: 我用VBA制作了一个简单的函数,但这还远远不够完美 Function MathematicaPosition(lookvalue As Range, TableRange As Range, RowOrColumn As Boolean) As Integer Dim r As Integer

我有一个Excel表格,其中有列标题、行标题和相应的值。如何在Excel中查找表中的列标题和行标题名称/按值索引

在Mathematica中,等价函数是位置[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

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


直接从

假设数据数组位于A1:D5:

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

在G4中:
=IF(ROWS($G$4:G4)>$G$2,”,索引($A$2:$A$5,INT(SMALL)(IF($B$2:$D$5=$G$1,(ROW($B$2:$D$5)-ROW($B$2)+1)*10^5+列($B$2:$D$5)-列($B$2)+1),行($G$4:G4))

在H4中:
=IF(行($G$4:G4)>$G$2,”,索引($B$1:$D$1,MOD(小型)(IF($B$2:$D$5=$G$1,(行($B$2:$D$5)-行($B$2)+1)*10^5+列($B$2:$D$5)-列($B$2)+1),行($G$4:G4)),10^5)

后两者使用Ctrl+Shift+Enter输入并向下复制


我不知道Mathematica,也不理解反向值(基本上是乘以-1还是转换列)。

双重查找确实会反向。我需要基于表中的值的列和行的索引。这使用数组公式,这对于大型数据集的操作非常笨拙。此外,公式看起来不可读且不通用。为什么公式中有10^5的乘数?为什么删除Mathematica标记?
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