trimming arrays within cell
Ältere Kommentare anzeigen
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 Kommentar
Adam
am 15 Mär. 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.
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Solver Outputs and Iterative Display finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!