trimming arrays within cell
古いコメントを表示
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 件のコメント
Adam
2016 年 3 月 15 日
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.
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Solver Outputs and Iterative Display についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!