Get the index of one cell of a cell array
2 次查看(过去 30 天)
显示 更早的评论
Hi,
From a given cell of a cell array, how is it possible to easily and quickly get its index ?
Thanks for help.
Best.
2 个评论
Johannes Hougaard
2020-5-4
Try reading the help for ind2sub or sub2ind
These functions are valid for cell arrays as well.
采纳的回答
Ameer Hamza
2020-5-4
Suppose you have a cell array
A = {1,2,3,4,5};
and you extract a specific element of this array
a = A(4);
then, for a general case, you can find its index back using
idx = find(cellfun(@(x) isequal(x,a{:}), A))
if all the elements of A are scalar, then you can also write
idx = find([A{:}]==a{1});
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!