MATLAB Answers

How to replace multiple duplicate rows with single row?

2 views (last 30 days)
kahar
kahar on 3 Dec 2019
Edited: Adam Danz on 5 Dec 2019
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

  0 Comments

Sign in to comment.

Accepted Answer

Adam Danz
Adam Danz on 4 Dec 2019
Edited: Adam Danz on 4 Dec 2019
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

More Answers (0)

Sign in to answer this question.