How to find number and position from cell

조회 수: 2 (최근 30일)
Philip
Philip 2013년 2월 28일
I have a large cell file (1.6*10^6 rows) with only ones and []. I want to find the positions of the ones, preferably converted to ones and zeros. Since it's a large file, I would rather not do it in a loop.
Example:
a = [1 1 [] [] 1]
have ones in position 1,2,5
  댓글 수: 1
Jan
Jan 2013년 2월 28일
편집: Jan 2013년 2월 28일
A cell requires curly braces, because [1 1 [] [] 1] is the same as [1,1,1].

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

답변 (1개)

Jan
Jan 2013년 2월 28일
편집: Jan 2013년 2월 28일
a = {1, 1, [], [], 1};
index = find(~cellfun('isempty', a));
Perhaps this is slightly faster:
index = find(cellfun('prodofsize', a));
While this is slower:
index = find(cellfun(@(c) isequal(c, 1), a));
  댓글 수: 1
Philip
Philip 2013년 2월 28일
Thank a lot, this worked out fine!

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

카테고리

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