Hi guys
In the version of R2012a, the unique function has a 'stable' property. Please see the link:
A = [9 2 9 5]; [C, ia, ic] = unique(A,'stable')
C =
9 2 5
ia =
1
2
4
ic =
1
2
1
3
But my matlab version is R2010a, it seems that the unique function in R2010a does not support 'stable'. How can I get the stable result?
Thanks,

댓글 수: 4

Sean de Wolski
Sean de Wolski 2012년 7월 31일
편집: Sean de Wolski 2012년 7월 31일
You could always upgrade to 12a :)
Paul Cisek
Paul Cisek 2017년 1월 21일
Or even better - Mathworks could stop pointlessly changing the functionality of their software ;-)
Guillaume
Guillaume 2017년 1월 21일
It's hardly pointless, and it was the addition of a new option to an existing function which is perfectly fine.
Code written for R2010a unique works exactly the same in R2012a
Walter Roberson
Walter Roberson 2017년 1월 21일
Paul Cisek: how would you envision that working? You seem to be implying that Mathworks should only make bug fixes and performance improvements that do not change the output at all (even at the round-off level.) Does that sound like a route to financial viability?

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

답변 (2개)

Albert Yam
Albert Yam 2012년 7월 31일

1 개 추천

I needed this as well, for R2007a
[uA a b] = unique(A,'first');
C = A(sort(a));
Sean de Wolski
Sean de Wolski 2012년 7월 31일

0 개 추천

The 'stable' option was introduced in R2012a.
One way to achieve something similar with an older release is to first sort the vector, then unique it and then index back into the original.
A = [9 2 9 5 5 4 4 1 1 1];
[As,idx] = sort(A);
[U,ij] = unique(As,'first');
A(sort(idx(ij)))

카테고리

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

태그

질문:

2012년 7월 31일

댓글:

2017년 1월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by