필터 지우기
필터 지우기

index position of the 1

조회 수: 1 (최근 30일)
khaled hassan
khaled hassan 2016년 11월 7일
댓글: Walter Roberson 2016년 11월 7일
Hi,
I have the following cell array
TEST = [1] [] [] [0] []
I want to get the index position of the 1 not the 0. thanks :) !

채택된 답변

Walter Roberson
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) )

추가 답변 (2개)

KSSV
KSSV 2016년 11월 7일
TEST = {[1] [] [] [0] []} ;
% index position of 1
idx = find([TEST{:}] == 1)
  댓글 수: 1
Walter Roberson
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.

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


khaled hassan
khaled hassan 2016년 11월 7일
thank you a lot :) !!!!!!!!!!!!! it worked perfectly

카테고리

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