matlab cell不支持find查找的解决方案

可利用下面这段代码进行cell中的查找,可直接复制使用。

function [ row, col ] = findInCell( var,cellArray )
% Description: Find the index of element in a cell array
% Input: var: value to be seached
%        cellArray: cell array to search var
% Output: row: row index 
%         col: corresponding column index
% demo: suppose A and B are two cell arraies,
%       [x y] = findInCell(A{1},B) searches the first element of A in B

[row,col] =ind2sub(size(cellArray),find(cellfun(@(x)strcmp(x,var),cellArray)));

end

发布了7 篇原创文章 · 获赞 0 · 访问量 404

猜你喜欢

转载自blog.csdn.net/weixin_44035267/article/details/104535156