How to find unique value in serial order??
조회 수: 1 (최근 30일)
이전 댓글 표시
I have a matrix
p = [90 90 -45 0 0 45 45 0 -45];
i want unique values in serial order from right side
q = [90 -45 0 45 0 -45];
Means from right side first value is -45, second is 0, third is 45...etc
I want repeated unique number according to serial from RHS.
Means sort repeated values.
댓글 수: 0
채택된 답변
the cyclist
2016년 1월 26일
편집: the cyclist
2016년 1월 26일
Does this do what you want?
p = [90 90 -45 0 0 45 45 0 -45];
idx = [true diff(p)~=0];
q = p(idx);
If not, can you give another example or two that illustrates the rule?
댓글 수: 2
the cyclist
2016년 1월 26일
Is this a homework problem? If so, can you show some work that you tried yourself?
You can see my comment on Walter's solution, to see the way to get q.
추가 답변 (1개)
Walter Roberson
2016년 1월 26일
q = p;
q(1+find(q(1:end-1)==q(2:end))) = [];
댓글 수: 2
the cyclist
2016년 1월 26일
p = [90 90 -45 0 0 45 45 0 -45];
pLR = fliplr(p);
idxLR = [true diff(pLR)~=0];
locationsLR = find(fliplr(idxLR))
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!