trimming arrays within cell
Mostrar comentarios más antiguos
I have a cell array containing many vectors (traces). I would like to use another cell array, containing the index of the first useful number in each vector, to trim the beginning of each vector.
a for-loop method would be:
for t = 1:numel(traces)
traces{t} = traces{t}(first{t}:end)
end
but this is ugly and I feel like there must be a non-for-loop based way of doing this, perhaps using cellfun?
1 comentario
Adam
el 15 de Mzo. de 2016
It depends why you want to replace the for loop. cellfun can usually replace a loop around a cell array if you want it to, but it is usually slower so if speed is your motivation then this is unlikely to help, though obviously it is always worth implementing the two alternatives to test their speed.
For cellfun just create a function of two variables, the vector and the scalar first useful number and run cellfun over your two arrays using this.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!