Use vectorization. Matlab is designed for vectorized operations, that are much faster than loops. Test to resolve issues employing vectorized functions When doable. -coordinates, specify the shared coordinates like a vector and one other coordinates like a matrix. The duration from the vector need to match amongst the size in https://simonlbtmt.blogdosaga.com/28094290/the-2-minute-rule-for-matlab-online-help