index position of the 1
1 次查看(过去 30 天)
显示 更早的评论
Hi,
I have the following cell array
TEST = [1] [] [] [0] []
I want to get the index position of the 1 not the 0. thanks :) !
0 个评论
采纳的回答
Walter Roberson
2016-11-7
find( cellfun(@(C) numel(C) == 1 && C == 1, TEST) )
In the special case where each entry is only empty or a scalar, then
find( cellfun(@(C) C == 1, TEST) )
If you want to find a 1 anywhere in the cell:
find( cellfun(@(C) any(C == 1), TEST) )
0 个评论
更多回答(2 个)
KSSV
2016-11-7
TEST = {[1] [] [] [0] []} ;
% index position of 1
idx = find([TEST{:}] == 1)
1 个评论
Walter Roberson
2016-11-7
If you switch to
TEST = {[0] [] [] [1] []} ;
then [TEST{:}] would be [0 1] and you would return an index of 2, but the actual index should be 4.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!