find in cell array
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
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 件のコメント
その他の回答 (1 件)
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);
Please try it out :)
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Matrices and Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!