array/cellfun vs. for loop
    20 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    David Goldsmith
      
 el 28 de Jun. de 2012
  
    
    
    
    
    Comentada: Rik
      
      
 el 20 de Ag. de 2018
            Are arrayfun and cellfun always faster than functionally equivalent for loops? If so, why? (E.g., is it a difference in the library functions they call for implementation?) Finally, is it possible to give a general "order function" by which they're faster (e.g., O(N), O(NlogN), etc.)?
0 comentarios
Respuesta aceptada
  Walter Roberson
      
      
 el 28 de Jun. de 2012
        For loops are usually faster than arrayfun or cellfun, as the for loop does not need to invoke the function handle each time. The for loop also has opportunities for optimizations between statements that the arrayfun or cellfun would not have.
arrayfun() or cellfun() can be faster to write the code for, as they are a higher level concept. Not always, though: some of the twists one has to go through to create the behaviour as an anonymous function can be messy.
8 comentarios
Más respuestas (0)
Ver también
Categorías
				Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
			
	Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!






