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

1 回表示 (過去 30 日間)
Nguyen Anh Cuong
Nguyen Anh Cuong 2019 年 4 月 26 日
編集済み: KALYAN ACHARJYA 2019 年 4 月 26 日
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 件のコメント
madhan ravi
madhan ravi 2019 年 4 月 26 日
編集済み: madhan ravi 2019 年 4 月 26 日
@Kalyan: No, the OP wants no 8
"you can merge the statements in single line"
How?, other than commas / semicolons
KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 4 月 26 日
sorry I misunderstood @madhan OK.

サインインしてコメントする。

採用された回答

Andrei Bobrov
Andrei Bobrov 2019 年 4 月 26 日
編集済み: Andrei Bobrov 2019 年 4 月 26 日
In your case:
[~,~,vec2] = unique(vec);
  1 件のコメント
Nguyen Anh Cuong
Nguyen Anh Cuong 2019 年 4 月 26 日
Ohhh! Thank you for helping me solve this problem very quickly and simply.
[~,~,vec2] = unique(vec);
vec2=vec2'
Tks

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by