Effacer les filtres
Effacer les filtres

find in cell array

5 vues (au cours des 30 derniers jours)
NA
NA le 20 Mar 2019
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]};

Réponse acceptée

KSSV
KSSV le 20 Mar 2019
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) = []

Plus de réponses (1)

Raghunandan V
Raghunandan V le 20 Mar 2019
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 :)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by