Effacer les filtres
Effacer les filtres

removing element from all arrays in cell array of 1-dimensional arrays

1 vue (au cours des 30 derniers jours)
I have a cell array out = cell(n,1), and each out{j}, 1<= j <= n, is a vector of integers. These vectors have different lengths. How can I efficiently remove an integer k from all vectors containing k?

Réponse acceptée

Andrei Bobrov
Andrei Bobrov le 4 Mai 2012
newout = cellfun(@(x)setdiff(x,k),out,'un',0);

Plus de réponses (1)

Jan
Jan le 4 Mai 2012
for i = 1:n
v = out{i};
out{i} = v(v ~= k);
end
I assume 1. that a smarter cellfun approach is slower and 2. that spending more time for programming a faster solution (if there is any) will not pay off, except that this function is called trillions of times.
  1 commentaire
Kees Roos
Kees Roos le 4 Mai 2012
Thanks! Your remark on cellfun turns out to be true. But in my case, where n=1000, the for loop takes also too much time. I was hoping for a 'vectorized' solution.

Connectez-vous pour commenter.

Catégories

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