im trying to create a function that wors the same way as the unique() function without using it
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
haarn sumhah
am 8 Apr. 2022
Bearbeitet: Davide Masiello
am 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 Kommentare
Akzeptierte Antwort
Davide Masiello
am 8 Apr. 2022
Bearbeitet: Davide Masiello
am 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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Stress and Strain finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!