I have a matrix:
mat = [ 2009 3 ;
2010 2 ] ;
I need to repeat the Col1 as per Col2. The solution at Repeat copies of array elements: Run-length decoding in MATLAB is helpful. However, my main problem is to then increment the years according, as in:
Ansmat = [ 2009 3
2010 3
2011 3
2010 2
2011 2 ] ;
I want to avoid a for loop here. Thanks for your help! This would be a great help!
You can first replicate your matrix using my vectorized answer to the previous question:
Next, you can create a column vector of offsets to add to the dates in the first column. Here’s how you can do this in a vectorized way.