How can I count the followed occurrences of each element in a vector in MATLAB?
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi, I want to count the number of followed occurrences of each element in a vector.
So if my input is
x = [1 1 1 2 2 1 1 2 5 5]
I need an output
y = [1 2 1 2 5;3 2 2 1 2] How do I do this?
댓글 수: 2
William
2015년 11월 30일
check out this post : http://www.mathworks.com/matlabcentral/answers/34302-how-to-find-consecutive-numbers
채택된 답변
Stephen23
2015년 11월 30일
편집: Stephen23
2015년 11월 30일
x = [1 1 1 2 2 1 1 2 5 5];
f = [find(diff(x)),numel(x)];
y(2,:) = [f(1),diff(f)];
y(1,:) = x(f);
which generates this output:
>> y =
1 2 1 2 5
3 2 2 1 2
추가 답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!