I have a matrix with Col1 IDs and Col2 Values.
mat = [ ...
1000 3
1000 4
1000 nan
1000 nan
1000 5
2222 1
2222 2
2222 nan
3333 nan
4444 1 ] ;
I need to replace nan with the value in the row above it, but subject to the condition: row above should have the same ID.
Answer:
mat = [ ...
1000 3
1000 4
1000 4
1000 4
1000 5
2222 1
2222 2
2222 2
3333 nan
4444 1 ] ;
Can you suggest a vectorized approach?