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 Center および File ExchangeData Type Identification についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by