# find in cell array

5 ビュー (過去 30 日間)
Naime 2019 年 3 月 20 日
Answered: Raghunandan V 2019 年 3 月 20 日
A={[1,2,3,4,5],[1,3],[1],[1,3,4,5,6,7,89,0],[1,3],[1,3,4,5],[4,6]};
MM = cellfun(@(m)find(numel(m)==2),A,'uni',0);
b= cellfun(@(m,t)m(~t),A,MM,'uni',0);
I want to omit all array that has size 2 from b.
result should be
b={[1,2,3,4,5],[1],[1,3,4,5,6,7,89,0],[1,3,4,5]};

#### 0 件のコメント

サインイン to comment.

### 採用された回答

KSSV 2019 年 3 月 20 日
A={[1,2,3,4,5],[1,3],[1],[1,3,4,5,6,7,89,0],[1,3],[1,3,4,5],[4,6]};
N = cellfun(@length,A) ;
A(N==2) = []

#### 0 件のコメント

サインイン to comment.

Raghunandan V 2019 年 3 月 20 日
Hi,
The simple problem with your code is it is not able to extract the indices of the value 1 which has been obtained by MM. I have made a small improvization on your code. check it out!
% input
A={[1,2,3,4,5],[1,3],[1],[1,3,4,5,6,7,89,0],[1,3],[1,3,4,5],[4,6]};
% find the indices of matrix with size two inside a cell
MM = cellfun(@(m)find(numel(m)==2),A,'uni',0);
% find the empty matrices from MM
C = cellfun('isempty',MM);
% get the indices of non zero matrices
Index = find(C);
%Now finally the output
b = A(Index);