Effacer les filtres
Effacer les filtres

removing for loop by using cellfun

1 vue (au cours des 30 derniers jours)
Richard
Richard le 30 Avr 2012
Could anyone provide information on how to remove the for loop from this line of script:
for i =1:length(Name);
Data{i} = arrayfun(@(j)mean(temp{i}(j,1:bin{i(j))),1:length(bin{i}),'un',1);
end
I have tried:
Data = arrayfun(@(j)cellfun(@(a,b)mean(a(j,1:b(j))),1:lenth(b),'un',1),temp,bin,'un',0);
An error returns:
Too many input arguments.
How would I remove the loop?
  4 commentaires
Daniel Shub
Daniel Shub le 30 Avr 2012
I am not sure if arrayfun is much faster than a loop with proper preallocation.
Oleg Komarov
Oleg Komarov le 30 Avr 2012
I think a for loop should be faster and definitely more readable in this case.
However, 1:bin{i(j))) has a typo and i(j) doesn't make sense since "i" is always a scalar.

Connectez-vous pour commenter.

Réponse acceptée

Andrei Bobrov
Andrei Bobrov le 30 Avr 2012
Data = cellfun(@(x,y)arrayfun(@(jj)mean(x(jj,1:y(jj))),1:length(y)),temp,bin,'un',0);

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices 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