How to reset the sequence number for the sequence number in vector?

1 view (last 30 days)
Reset the sequence number
I have 1 vector:
vec=[1, 2, 3, 4, 2, 1, 3, 8, 7, 9]
(lost 2 consecutive numbers 5, 6)
I want to reassign the above vector so that the sequence number is continuous.
That is, the above vector must be reset:
vec2=[1, 2, 3, 4, 2, 1, 3, 6, 5, 7]
How to do it, please help.
  5 Comments
madhan ravi
madhan ravi on 26 Apr 2019
Edited: madhan ravi on 26 Apr 2019
@Kalyan: No, the OP wants no 8
"you can merge the statements in single line"
How?, other than commas / semicolons

Sign in to comment.

Accepted Answer

Andrei Bobrov
Andrei Bobrov on 26 Apr 2019
Edited: Andrei Bobrov on 26 Apr 2019
In your case:
[~,~,vec2] = unique(vec);
  1 Comment
Nguyen Anh Cuong
Nguyen Anh Cuong on 26 Apr 2019
Ohhh! Thank you for helping me solve this problem very quickly and simply.
[~,~,vec2] = unique(vec);
vec2=vec2'
Tks

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!