im trying to create a function that wors the same way as the unique() function without using it

2 次查看(过去 30 天)
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

采纳的回答

Davide Masiello
Davide Masiello 2022-4-8
编辑:Davide Masiello 2022-4-8
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)
uniqueA = 1×9
1 2 3 4 5 6 7 8 9
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 个)

类别

Help CenterFile Exchange 中查找有关 Stress and Strain 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by