omit nonzero elemnt in cell

3 vues (au cours des 30 derniers jours)
NA
NA le 28 Juin 2019
A={[3,4],[8,9],[1,2],0,0,0};
A(cell2mat(A)==0)={[]};
I used this code, but have error
Error using cat
Dimensions of arrays being concatenated are not consistent.
Error in cell2mat (line 2)
m{n} = cat(2,c{n,:});
Result should be
A={[3,4],[8,9],[1,2],[],[],[]};

Réponse acceptée

Andrei Bobrov
Andrei Bobrov le 28 Juin 2019
A(cellfun(@(x)numel(x) == 1 && x == 0,A)) = {[]};

Plus de réponses (1)

Himanshu tripathi
Himanshu tripathi le 28 Juin 2019

Catégories

En savoir plus sur Data Types 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