I have a column of numbers [1 1 2 2 3 1 2 3 3 4 1 1 2] and I want to change the numbers so that they are in sequential order, resulting in [1 1 2 2 3 4 5 6 6 7 8 8 9]. How can I do this?

답변 (2개)

Walter Roberson
Walter Roberson 2015년 5월 22일

2 개 추천

sort()

댓글 수: 3

Andrew
Andrew 2015년 5월 22일
Perhaps I could have phrased my question topic better, but I do not think this method would solve my problem.
Suppose the vector is stored in t. Then
Ordered = cumsum([1; diff(t(:))~=0]);
Stephen23
Stephen23 2015년 5월 22일
@Andrew: can you please explain how Walter Roberson's solution does not "solve my problem". Please tell us what you want it to do, or how it should be different.
What exactly is the problem then?

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

Andrei Bobrov
Andrei Bobrov 2015년 5월 22일

0 개 추천

a = [1 1 2 2 3 1 2 3 3 4 1 1 2];
z = [0 3 7];
out = z(cumsum(diff([0,a == 1]) == 1)) + a;

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

질문:

2015년 5월 22일

댓글:

2015년 5월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by