How to reset the sequence number for the sequence number in vector?
1 view (last 30 days)
Show older comments
Nguyen Anh Cuong
on 26 Apr 2019
Edited: KALYAN ACHARJYA
on 26 Apr 2019
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
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
Accepted Answer
Andrei Bobrov
on 26 Apr 2019
Edited: Andrei Bobrov
on 26 Apr 2019
In your case:
[~,~,vec2] = unique(vec);
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!