How to replace multiple duplicate rows with single row?

Hi,
I have a table with a row containing multiple values, such as below.
0
10
10
10
10
10
14
6
10
10
10
4
... and so on.
I need to replace the multiple rows of 10 with just a single 10, like so.
0
10
14
6
10
6
...
I know unique doesn't work as I can't put a condition it to work between two rows that don't have 10. So any help would be greaty appreciated. Thanks in advance!
Kahar

 採用された回答

Adam Danz
Adam Danz 2019 年 12 月 4 日
編集済み: Adam Danz 2019 年 12 月 4 日

0 投票

x = [0
10
10
10
10
10
14
6
10
10
10
4];
x([1;diff(x)]==0) = [];
% x =
% 0
% 10
% 14
% 6
% 10
% 4

2 件のコメント

kahar
kahar 2019 年 12 月 4 日
That worked a treat. Thank you so much!
Adam Danz
Adam Danz 2019 年 12 月 4 日
編集済み: Adam Danz 2019 年 12 月 5 日
Glad I could help!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeShifting and Sorting Matrices についてさらに検索

質問済み:

2019 年 12 月 3 日

編集済み:

2019 年 12 月 5 日

Community Treasure Hunt

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

Start Hunting!

Translated by