How to find the position in cell arry?
조회 수: 3 (최근 30일)
이전 댓글 표시
Hi
I have cell array data example. D = {[1 2];[1 4];[1 6];[2 4];[2 5];}
I want to find the position of [1 6] in that D, and the answer is 3.
I try this command
suppose c = [1 6]
cellfun(@(x) ismember(x,c),D,'UniformOutput',false)
and the output is below
[0] [0] [1] [0] [0]
but I want the answer is 3
how to do it?
thank you
댓글 수: 0
채택된 답변
Honglei Chen
2012년 6월 25일
D = {[1 2];[1 4];[1 6];[2 4];[2 5];}
c = [1 6]
[~,~,idx] = intersect(c,cell2mat(D),'rows')
댓글 수: 3
Honglei Chen
2012년 6월 25일
~ is introduced recently, indicating that the output is not needed in successive steps. If it errors out, you can just use any variable name you want, as you have tried.
추가 답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!