im trying to create a function that wors the same way as the unique() function without using it
1 view (last 30 days)
Show older comments
haarn sumhah
on 8 Apr 2022
Edited: Davide Masiello
on 8 Apr 2022
i first wrote it as a stand along program
clear, clc
nput = [1 2 3 4 4 5 5 6 7 8 9];
%function bmatch = findmatch(nput)
q = intersect(nput,nput);
sim = 1 - isequal(q,nput);
if sim == 0;
disp('0')
else sim == 1;
disp('1')
end
then tried to change it to a function but couldnt get it to output anything please help
clear, clc
nput = [1 2 3 4 5 6 7 8 2 9];
function sim = ismatch(nput)
q = intersect(nput,nput);
sim = 1 - isequal(q,nput);
if sim == 0;
disp('0')
else sim == 1;
disp('1')
end
end
0 Comments
Accepted Answer
Davide Masiello
on 8 Apr 2022
Edited: Davide Masiello
on 8 Apr 2022
This is rudimentary, but it might be a starting point.
clear, clc
A = [1 2 3 4 5 6 7 8 2 9 2 1 5];
uniqueA = ismatch(A)
function out = ismatch(A)
B = A == A';
B(logical(eye(size(B))) | logical(tril(ones(size(B))))) = 0;
out = A(~any(B,1));
end
However, it still does not do eveything that unique does (sort output, indexes of duplicates etc.).
0 Comments
More Answers (0)
See Also
Categories
Find more on Stress and Strain in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!