Filter löschen
Filter löschen

index position of the 1

1 Ansicht (letzte 30 Tage)
khaled hassan
khaled hassan am 7 Nov. 2016
Kommentiert: Walter Roberson am 7 Nov. 2016
Hi,
I have the following cell array
TEST = [1] [] [] [0] []
I want to get the index position of the 1 not the 0. thanks :) !

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 7 Nov. 2016
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) )

Weitere Antworten (2)

KSSV
KSSV am 7 Nov. 2016
TEST = {[1] [] [] [0] []} ;
% index position of 1
idx = find([TEST{:}] == 1)
  1 Kommentar
Walter Roberson
Walter Roberson am 7 Nov. 2016
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.

Melden Sie sich an, um zu kommentieren.


khaled hassan
khaled hassan am 7 Nov. 2016
thank you a lot :) !!!!!!!!!!!!! it worked perfectly

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by