Find a series of consecutive numbers and change index of them
Show older comments
Hi,
I have this kind of data. The first column and second column of the data refers to Index and time series(not consecutive) relatively.
Data = [1 1; 1 2; 1 3; 1 5; 1 6; 1 10; 1 11; 1 13; 1 20; 1 21; 1 22;];
I'd like to change this index number using Matlab code(to apply to thousands of data) when the value of the second colmn is not consecutive numbers.
So in my example, the first column should be changed [1; 1; 1; 2; 2; 3; 3; 4; 5; 5; 5;] .
If anyone can help, it would be greatly appreciated.
Thank you!
Accepted Answer
More Answers (1)
Andrei Bobrov
on 12 Aug 2019
[~,~,Data(:,1)] = unique(cumsum(Data(:,1)) - Data(:,2),'stable');
Categories
Find more on Biological and Health Sciences in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!