### Translated by

このページのコンテンツは英語から自動翻訳されています。自動翻訳をオフにする場合は「<a class="turn_off_mt" href="#">ここ</a>」をクリックしてください。

## Removing repeating data points but keeping the first and last ones

Andrew Luce

### Andrew Luce (view profile)

さんによって質問されました 2019 年 5 月 20 日 21:10

### Adam Danz (view profile)

さんによって 編集されました 2019 年 6 月 11 日 13:40
Hello, say I have matrix with repeating parts in the frist and second row and all zeros in the third
A=1,2,3,4,5,6,7,8,9,1,1,1,1,1,1,1,1,1,3,4,5,6
9,9,9,9,9,9,9,9,9,2,3,4,5,6,7,8,9,8,2,2,2,2
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
I want to keep the columns where there is no repeating in the column before and after. Additonally, I want to keep the columns where the repeating starts and ends. The resulting matrix would look like this in the end
A=1,9,1,1,3,6
9,9,2,8,2,2
0,0,0,0,0,0
How would I get this
thank you

Image Analyst

### Image Analyst (view profile)

2019 年 5 月 20 日 22:30
What if your criteria would result in the first and second row having different numbers of elements?

### Adam Danz (view profile)

2019 年 5 月 20 日 23:03
I wondered that, too. For example,
A=[ 1,2,3,4,5,6,7,1,1,1,1,1,1,1,1,1,1,1,3,4,5,6;
9,9,9,9,9,9,9,9,9,9,9,4,5,6,7,8,9,8,2,2,2,2;
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
% ^ ^ ^ ^
Is that an example of what you were thinking, Image Analyst?
My answer removes columns in any of the rows have repeats (but keeps the first and last ones).
so,
Ap = 1 1 3 6
9 8 2 2
0 0 0 0

サインイン to comment.

R2019a

## 1 件の回答

### Adam Danz (view profile)

2019 年 5 月 20 日 21:29

### Adam Danz (view profile)

2019 年 6 月 11 日 13:40

A is your input matrix, Ap is the trimmed matrix.
isUnq = find(~any(diff(A([1,2],:),[],2)==0, 1))+1;
keepColIdx = unique([1,isUnq, isUnq-1, size(A,2)]);
Ap = A(:,keepColIdx);
Result
Ap =
1 9 1 1 3 6
9 9 2 8 2 2
0 0 0 0 0 0

#### 0 件のコメント

サインイン to comment.

Translated by