필터 지우기
필터 지우기

How to find index of a value in cell array

조회 수: 68 (최근 30일)
Vishal Sharma
Vishal Sharma 2017년 1월 25일
댓글: Kristoffer Walker 2019년 12월 13일
I have this Cell Array ‘A’ of size 3 by 7
A = { 3 4 [] [] [] [] []
2 6 -2 2 -2.1 2 2
-5 -5 25 1 [] [] []}
I want to find index of ‘6’ element in 2nd row and 2nd column The answer shall be row = 2 and column = 2

채택된 답변

the cyclist
the cyclist 2017년 1월 25일
편집: the cyclist 2017년 1월 25일
isSix = cellfun(@(x)isequal(x,6),A);
[row,col] = find(isSix);
  댓글 수: 3
hyunglok kim
hyunglok kim 2018년 3월 26일
This answer is the best.
Kristoffer Walker
Kristoffer Walker 2019년 12월 13일
Not at all intuitive, but it works great, even for logicals.

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2017년 1월 25일
Re-using the framework of my answer to your earlier question:
B = A;
B(cellfun(@isempty, B)) = {NaN};
[maxrow, maxcol] = find( reshape(cell2mat(B), [], 1) == 6);

카테고리

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