finding the index of an array in cell array

조회 수: 1 (최근 30일)
Izzat Brgli
Izzat Brgli 2021년 3월 28일
댓글: Stephen23 2021년 3월 30일
I'm trying to find out if an array is an element of a cell array and return the index, so I did
arr ={[1,2,3],[4,45,6]}
index = find([arr{:}] == [1,2,3])
but it didn't work. How can I solve it?
thanks in advance

채택된 답변

Fangjun Jiang
Fangjun Jiang 2021년 3월 29일
편집: Fangjun Jiang 2021년 3월 29일
arr ={[1,2,3],[4,45,6]};
>> index=find(cellfun(@(x) all(x==[1 2 3]),arr))
index =
1
  댓글 수: 1
Stephen23
Stephen23 2021년 3월 30일
Simpler and more efficient to use isequal:
arr = {[1,2,3],[4,45,6]};
vec = [1,2,3];
fun = @(a)isequal(vec,a);
idx = cellfun(fun,arr)
idx = 1×2 logical array
1 0

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by