Indexing way to retrieve indices of nonempty elements of a cell array?
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Is there an indexing way (I couldn't figure one out) to do what this little function does:
function nonempty = findNonEmpty(cellarray)
% Find indices of non-empty array elements of cellarray
% Example:
% findNonEmpty({[], {3}, [], [], eye(100)}) returns [2 5]
nonempty = [];
for i=1:length(cellarray)
if ~isempty(cellarray{i})
nonempty(end+1) = i;
end
end
0 commentaires
Réponse acceptée
Fangjun Jiang
le 29 Juil 2011
a={[], {3}, [], [], eye(100)};
b=find(~cellfun('isempty',a))
0 commentaires
Plus de réponses (1)
Voir également
Catégories
En savoir plus sur Matrix Indexing 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!