Remove repeating values from vectors

1 回表示 (過去 30 日間)
Andrew Poissant
Andrew Poissant 2017 年 8 月 3 日
コメント済み: Andrew Poissant 2017 年 8 月 3 日
I have two vectors, r and c, which have repeating patterns in them. c repeats the same number 3 times and then increases by 4, and repeats. r has three increasing numbers, and those three increasing numbers are repeated 3 times. The vectors are seen below. How do I remove repeating values in each? The resulting vectors should be c = [670; 674; 678] and r = [649; 652; 655].
c = [670; 670; 670; 674; 674; 674; 678; 678; 678];
r = [649; 652; 655; 649; 652; 655; 649; 652; 655];

採用された回答

Jan
Jan 2017 年 8 月 3 日
編集済み: Jan 2017 年 8 月 3 日
c = [670; 670; 670; 674; 674; 674; 678; 678; 678];
r = [649; 652; 655; 649; 652; 655; 649; 652; 655];
c = unique(c, 'stable');
r = unique(r, 'stable');
Why do you ask for 2 vectors? Whould the pattern in one vector be considered in the other one? Or are they independent from each other?
Can the same value appear at multiple locations, but should be accepted then? In other words, what is the wanted output for:
v = [1, 1, 2, 2, 2, 1]
v = RunLength(v);
Or:
function x = NonRep(x)
if ~isempty(x)
x = x([true; diff(x(:)) ~= 0]);
end
end
c = NonRep(c);
  1 件のコメント
Andrew Poissant
Andrew Poissant 2017 年 8 月 3 日
For the purposes of my work I need two separate vectors. Your answer did the trick, thanks!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by