Azzera filtri
Azzera filtri

find in cell array

5 visualizzazioni (ultimi 30 giorni)
NA
NA il 20 Mar 2019
Risposto: Raghunandan V il 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]};

Risposta accettata

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

Più risposte (1)

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

Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by