find in cell array

1 次查看(过去 30 天)
NA
NA 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]};

采纳的回答

KSSV
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) = []

更多回答(1 个)

Raghunandan V
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 :)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by