【问题标题】:How to find the index of a cell (vector case) in Matlab如何在Matlab中找到单元格(向量案例)的索引
【发布时间】:2019-08-09 08:43:30
【问题描述】:

我只是搜索以下相关讨论:

  1. How do I find a specific cell within a cell array?.

    1. https://www.mathworks.com/matlabcentral/answers/84242-find-in-a-cell-array

但是,它们并不是我想要的。

v = [1 0]; u = [0 1];
C = {v, u; u, u+u}

我在上面创建了一个单元格 C,每个元素都有一个行向量。

如果我这样做了

C{2,2}

它显示

ans =

 0     2

相反,如果我知道[0 2],我想找到它在哪里,即我想得到{2,2},我该怎么做?

对于标量情况,答案显示在第二个链接中;但是,到目前为止,我找不到向量案例的答案。

谢谢!

【问题讨论】:

    标签: arrays matlab cell


    【解决方案1】:

    关注您链接的this answer,您可以这样做:

    found = cellfun(@(c) isequal(c,[0 2]),c)
    

    哪个输出

    
    found =
    
      2×2 logical array
    
       0   0
       0   1
    

    最后得到你将使用的坐标find

    [row,col] = find(found==1)
    

    输出将是

    row = 2
    col = 2
    

    【讨论】:

    • 又好又干净!谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多