Need help to specify unique values of a vector

조회 수: 1 (최근 30일)
Kostas
Kostas 2011년 11월 13일
I am using the unique command to specify the unique values of a vector that i read from different files. While it works ok for some of them, there are a lot that after i keep just the "unique" values i discover that there are still same values. The code i use is the following
idx=find(unique(Z));
Z=Z(idx);
My problem is that i use the Z variable for interpolation later in my code, so if the values aren't dinstict i get error
Error using ==> interp1 at 261 The values of X should be distinct.
Thank you in advance

채택된 답변

Fangjun Jiang
Fangjun Jiang 2011년 11월 13일
You probably didn't use the function right.
find() finds indices of nonzero elements. I don't know why you would run idx=find(unique(Z)).
unique() will return the unique values in Z, but it could also return the index. See the full help of unique().
  댓글 수: 1
Kostas
Kostas 2011년 11월 14일
You are right, i should use something like [b,idx]=unique(Z) to get indices in idx not find. Thanks a lot

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Workspace Variables and MAT-Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by