trimming arrays within cell
Show older comments
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 Comment
Adam
on 15 Mar 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.
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!