How to make array with first values of matrix
조회 수: 3 (최근 30일)
이전 댓글 표시
Hello to all,
I have a matrix for example like this: [1 2 3 4 5 6 7 8 9 10;2 2 3 3 4 5 5 2 3 3]' the first column represents time, the second ID of time. I need to make a cycle which goes through the matrix and takes the first time value from the group of ID of time.
So in this case the result will be: [1 3 5 6 8 9].
unique function is unfortunately not helpful in this case because the groups of ID of time might repeat.
Thank you very much
Filip
댓글 수: 1
Jan
2018년 2월 22일
Do not post multiple threads for one problem. See https://www.mathworks.com/matlabcentral/answers/384217-how-to-make-an-array-with-specific-matrix-values
답변 (1개)
C.J. Harris
2018년 2월 22일
% Input
A = [1 2 3 4 5 6 7 8 9 10;2 2 3 3 4 5 5 2 3 3]';
% Result
B = A([boolean(1); diff(A(:,2))~=0],1);
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!