How would I create my own 'unique' function without using the built in unique?
12 ビュー (過去 30 日間)
古いコメントを表示
I understand that the built in Unique function is stating that whatever function you define as unique is the same data set but without repetitions.
should I create a function file such as
function[unique,c] = myuni_1(A)
rows(A)= size(A,1);
columns(A) = size(A,2);
and then proceed to define the rows and columns as itself? I'm a bit confused here.
3 件のコメント
採用された回答
Jan
2014 年 4 月 30 日
A short version:
function U = myUnique(A)
[As, SV] = sort(A(:));
UV(SV) = ([1; diff(As)] ~= 0); % [1, As(2:nA) - As(1:nA-1)];
U = A(UV);
その他の回答 (2 件)
Walter Roberson
2014 年 4 月 29 日
Suppose you have two "bags", A and B. Start with A empty.
If B is empty, you are done and A holds the unique values. Otherwise, take one one item, C, out of B (removing it from B). Is there already a copy of C in A? If there is, then throw away C. Otherwise, add C to A. Now restart this paragraph.
Sean de Wolski
2014 年 4 月 30 日
編集済み: Sean de Wolski
2014 年 4 月 30 日
How about this?
x = [1 2 3 3 3 3 2 4 5];
[uv,ia] = intersect(x,x)
0 件のコメント
参考
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!