【问题标题】:Position function of Mathematica in Excel for matrix lookup by valueExcel中Mathematica的位置函数,用于按值查找矩阵
【发布时间】:2013-10-01 21:15:39
【问题描述】:

我在 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

【问题讨论】:

  • 为什么删除了 Mathematica 标签?

标签: excel lookup vba


【解决方案1】:

在此处查看双重查找部分:

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

【讨论】:

  • 双重查找确实反向。我需要基于表中的值的列和行索引。
【解决方案2】:

直接从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 还是切换列)。

【讨论】:

  • 这使用数组公式,对于大型数据集操作来说非常笨拙。此外,该公式看起来不可读且不通用。
  • 为什么你的公式中有 10^5 的乘数?
【解决方案3】:
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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-01-26
    • 1970-01-01
    • 1970-01-01
    • 2011-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多