MATLAB: Fast ways to generate multiple sequences without using for loop

loopsequences

Hi all,
Suppose, I have two arrays:
startIds = [x1, x2, x3]
endIds = [y1, y2, y3]
The two arrays have the same length and can be long. We may assume that (endIds(ii)-startIds(ii)) are the same for all positions ii. Is there any fast ways to generate multiple sequences without using for loop?
startIds(1):endIds(1)
startIds(2):endIds(2)
startIds(3):endIds(3)
Thanks!
-Thang

Best Answer

range = endIds(1) - startIds(1);
[t1, t2] = ndgrid(startIds, 0:range);
t3 = t1 + t2;