Retrieving element index in spfun, cellfun, arrayfun, etc. in MATLAB

后端 未结 3 1689
情书的邮戳
情书的邮戳 2021-02-07 13:06

Is there any way to retrieve the index of the element on which a function called by cellfun, arrayfun or spfun acts? (i.e

3条回答
  •  轮回少年
    2021-02-07 13:24

    You can create a sparse matrix with linear_index filling instead of values.

    Create A:

    A(find(S))=find(S)
    

    Then use A and S without spfun, e.g.: A.*S. This runs very fast.

提交回复
热议问题