How to remove repeating entries from a vector?

조회 수: 2 (최근 30일)
L'O.G.
L'O.G. 2023년 4월 17일
댓글: Image Analyst 2023년 4월 17일
How do you remove repeating entries in a vector?
For example: A = [1 1 1 0 0 1 1 1 1 0 0 0 0 0] should return B = [ 1 0 1 0].
The unique function does not do this from what I can tell. For the above example, it would return [0 1], which is not what I want.
  댓글 수: 1
Image Analyst
Image Analyst 2023년 4월 17일
Are the values always 1s and 0s? Or could you have something like [9,9,9,4,4,6,6,6,1,1,0,2,2]? If the latter would the result be [9,4,6,1,0,2]? What's the use case? Why do you need it? Is it your homework?

댓글을 달려면 로그인하십시오.

답변 (1개)

Matt J
Matt J 2023년 4월 17일
편집: Matt J 2023년 4월 17일
You can use this FEX download,
A = [1 1 1 0 0 1 1 1 1 0 0 0 0 0];
starts=groupLims(A);
B = A(starts)
B =
1 0 1 0

카테고리

Help CenterFile Exchange에서 Downloads에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by